Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Date.IsInPreviousDay Function Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Date.IsInPreviousDay function in Power Query checks whether a given date/time value falls within the previous calendar day relative to the current system time. It returns true or false and is useful for filtering datasets to include only records from yesterday—ideal for daily reports or data validation. This function requires Power Query in Excel or Power BI and works with DateTime or Date types; no additional tools or setup are needed.

What You'll Need

  • Microsoft Excel (2016 or later) with Power Query enabled, or Microsoft Power BI Desktop
  • A dataset loaded into Power Query containing at least one date/time column
  • Basic familiarity with editing Power Query queries (opening the Power Query Editor, adding custom columns)

Step-by-Step

  1. Open your Excel workbook or Power BI report and ensure the data you want to analyze is already loaded into Power Query. If not, go to the Data tab (in Excel) or Home tab (in Power BI), click Get Data, and import your source (e.g., Excel, CSV, database).
  2. Click the Data tab in Excel (or Home > Transform data in Power BI) to open the Power Query Editor.
  3. In the Queries pane on the left, click the name of the query containing your date column to open its editor window.
  4. 4. Identify the exact column name that holds your date or date/time values. Hover over the column header to confirm the name and data type (it should be DateTime or Date).
  5. Click Add Column > Custom Column from the ribbon to open the Custom Column dialog box.
  6. In the Custom column name field, enter a descriptive name such as IsYesterday.
  7. In the Custom column formula box, enter the function: Date.IsInPreviousDay([YourColumnName]). Replace YourColumnName with the actual column name (e.g., Date.IsInPreviousDay([OrderDate])). Ensure brackets surround the column name.
  8. Click OK. A new Boolean column will appear with true/false values indicating whether each row’s date equals yesterday’s date.
  9. To filter for only yesterday’s data, click the dropdown arrow in the new IsYesterday column header, uncheck false, and leave only true selected. Click OK. Your query now shows only rows where the date matches the previous calendar day.
  10. Click Close & Load (Excel) or Close & Apply (Power BI) to load the filtered data back into your workbook or report.

Common Mistakes

  • Using the wrong column name: Typos or case sensitivity issues (Power Query is case-sensitive for column names) will cause errors. Always copy-paste the column name from the column header or use the auto-complete suggestion after typing [.
  • Passing text instead of date/datetime: If your column is formatted as text (e.g., "2024-06-01"), the function returns an error. Convert the column to Date or DateTime type first using Transform > Data Type.
  • Assuming it uses a custom reference date: Date.IsInPreviousDay always compares against the system’s current date and time at query execution—there is no built-in way to override this unless you manually add a reference column.
  • Forgetting time zones: The function uses the local system time. If your data is stored in UTC and your system is in a different time zone, yesterday in your local time may not match yesterday in your dataset. You may need to convert time zones first using Date.AddZone or DateTimeZone.ToLocal.
  • Confusing "previous day" with "24 hours ago": Date.IsInPreviousDay checks the calendar day, not a rolling 24-hour window. For example, at 2 a.m. on June 2, it still considers all of June 1 as "previous day".

Tips

  • Use it alongside Date.IsInCurrentDay or Date.IsInNextDay for dynamic, relative date filtering (e.g., to compare today, yesterday, and tomorrow).
  • Combine with Table.SelectRows for programmatic filtering in advanced editing: Table.SelectRows(#"Previous Step", each Date.IsInPreviousDay(_[DateColumn])).
  • For repeated use, create a reusable parameter or function that wraps Date.IsInPreviousDay with a custom reference date if needed (e.g., to compare against a report date instead of today).
  • When troubleshooting, add a helper column with Date.ToText(Date.From([YourColumn])) to verify your date values are parsed correctly.
  • Use the Query Diagnostics feature (View > Diagnostics) to monitor execution and see if the function is causing performance issues on large datasets.

Troubleshooting

If you encounter errors or unexpected behavior, follow these steps:

  1. Check for #ERROR in the custom column: Hover over the error to see the message. If it says "Cannot convert value to Date", your column likely contains non-date values. Use Transform > Replace Values or Filter rows to clean non-date entries, or wrap the function in an error handler: try Date.IsInPreviousDay([DateColumn]) otherwise null.
  2. All values are false: Verify today’s date on your system (Windows: right-click clock > Adjust date/time). If your data contains dates from today or the future, they won’t match. Also check if your data is stored in a different time zone—convert it before applying the function.
  3. Function returns null: This means the input is null. Filter out nulls first (click the dropdown > uncheck Null) or use if [DateColumn] = null then false else Date.IsInPreviousDay([DateColumn]).
  4. Performance lag on large tables: Date.IsInPreviousDay itself is fast, but applying it to millions of rows may slow down preview. Try applying filters earlier in the query (e.g., reduce rows before adding the column) or use the Data Preview settings to load only a sample.
  5. Still not working after checking all above: Restart Excel or Power BI. Sometimes, the M engine caches outdated metadata. If the issue persists, recreate the query from scratch—copy the source, then rebuild the steps to avoid hidden corruption.

Frequently Asked Questions

Does Date.IsInPreviousDay work with date-only columns?

Yes. If your column is type Date (not DateTime), the function still evaluates the calendar day correctly. It treats the time as 12:00:00 a.m. by default.

Can I use Date.IsInPreviousDay to compare against a specific date (e.g., yesterday of a report date)?

Not directly. The function only compares to the current system date. To compare against a custom reference date (e.g., a parameter called ReportDate), subtract one day: Date.IsInPreviousDay([YourDate]) becomes Date.IsInPreviousDay(Date.AddDays(ReportDate, -1)) in a custom column (requires defining ReportDate as a parameter first).

Why does my function return true for today’s date?

It shouldn’t. If it does, your system clock is likely incorrect (e.g., set ahead by one day). Check your operating system’s date and time settings. If your data was imported from a server with a different time zone, you may need to adjust it before comparison.

Is Date.IsInPreviousDay case-sensitive or locale-dependent?

The function name itself is not case-sensitive in M code, but column names are. Locale settings (e.g., MM/DD vs DD/MM) affect how text dates are converted to Date values—but once the column is type Date, the function behaves consistently across locales.

Can I use this function in DAX or Power BI measures?

No. Date.IsInPreviousDay is a Power Query (M language) function and only works in the Power Query Editor. For DAX measures, use functions like DATEADD or PREVIOUSDAY in combination with TODAY().

Does this work in Power BI Service (online) queries?

Yes—but only if your data source is refreshed in Power BI Service. The function uses the service’s system time during refresh. If you need consistent behavior across time zones, set the dataset’s time zone under Dataset settings > Time zone.