Power Query DateTime.IsInPreviousMinute Function Explained
In this article
The DateTime.IsInPreviousMinute function in Power Query checks whether a given datetime value falls within the minute immediately before the current system time. It returns true or false based on that comparison, making it useful for filtering recent data streams or triggering time-sensitive logic in data refreshes. No additional setup is required beyond having Power Query available in Excel, Power BI, or Azure Data Factory.
What You'll Need
- Microsoft Excel 2016 or later, or Power BI Desktop (June 2020 or newer)
- A data source loaded into Power Query with at least one column containing datetime values
- Basic familiarity with the Power Query Editor interface
Step-by-Step
- Open your Excel workbook or Power BI file and navigate to the Power Query Editor by selecting Data > Get Data > Transform Data (in Excel) or clicking Edit Queries (in Power BI).
- Ensure your query contains a column with datetime values. If not, create one using Add Column > DateTime > Current DateTime to generate a reference point, or use an existing timestamp column from your source data.
- Select the column containing the datetime values you want to evaluate. If you’re working with a custom column, click on its header to highlight it.
- Go to the Add Column tab and click Custom Column.
- In the Custom Column dialog box, enter a name for your new column — for example,
IsInPreviousMinute. - In the Custom column formula box, type:
DateTime.IsInPreviousMinute([YourColumnName]). ReplaceYourColumnNamewith the exact name of your datetime column (e.g.,[EventTime]or[Timestamp]). - Click OK. A new column will appear with boolean values:
trueif the datetime falls within the previous minute relative to when the query was last refreshed, andfalseotherwise. - To filter for only records from the previous minute, click the dropdown arrow on the new column header, uncheck
false, and leave onlytrueselected. - Click Close & Load to apply the filter and load the results back into your worksheet or report.
- For dynamic use, ensure your data source refreshes frequently — the function evaluates against the system clock at refresh time, not at data load time.
Common Mistakes
- Using a text column instead of a datetime column — the function requires a true datetime type. If your column is formatted as text, convert it first using Transform > Data Type > Date/Time.
- Assuming the function compares to a static reference time — it always uses the system’s current time at the moment of query refresh. If you refresh at 10:01:30, it checks whether values are between 10:00:00 and 10:00:59.
- Forgetting to refresh the query after changing system time or data — the result won’t update unless you manually trigger refresh or have automatic refresh enabled.
- Trying to use the function in a calculated column in Power BI Data View — it only works in Power Query Editor during data transformation, not in DAX measures or calculated columns.
- Using it on time zones that differ from the system clock — if your data is stored in UTC but your system is set to EST, the function will use EST. Always standardize time zones before applying this function.
Tips
- Combine DateTime.IsInPreviousMinute with other time functions like DateTime.AddMinutes or DateTime.LocalNow to build more complex logic, such as checking if a record occurred within the last 90 seconds.
- Use this function for near-real-time dashboards in Power BI — it helps highlight the most recent batch of incoming data without requiring external triggers.
- Test the function with sample data by manually setting a known timestamp (e.g., 10:00:15) and refreshing the query just after the minute changes to verify expected behavior.
- When working with large datasets, apply the filter early in your query pipeline to reduce memory usage — filter for
trueright after creating the column. - Consider using DateTime.IsInPreviousMinute only if your data refreshes every minute or less. For hourly or daily refreshes, use DateTime.IsInPreviousHour instead for better accuracy.
- If you need to track events across multiple systems, ensure all systems involved have synchronized clocks (NTP enabled) to avoid false negatives.
Troubleshooting
- The function returns false for all rows even when data is recent — verify your datetime column is not null or improperly formatted. Use Remove Rows > Remove Blank Rows and ensure data type is Date/Time, not Text.
- Refresh doesn’t update the result — manually click Refresh All in Excel or Refresh in Power BI. If still not working, check if your data source requires authentication or has connectivity issues.
- Error: ‘We cannot apply operator
IsInPreviousMinuteto types Date and DateTime’ — this means the column is not recognized as datetime. Right-click the column header, choose Change Type > Date/Time. - Function works in Power BI but not in Excel — ensure your Excel version supports the function (2016 or later with updated Power Query). Older versions may not recognize newer M functions.
- Results vary between refreshes — this is expected. The function is time-sensitive. If you refresh at 14:00:05 and again at 14:01:02, the window of ‘previous minute’ shifts. This is not a bug — it’s the intended behavior.
- Blank results after filtering — check your system clock. If your computer’s time is behind or ahead by more than a minute, the function may not match any data. Adjust system time or use UTC for consistency.
Frequently Asked Questions
Can DateTime.IsInPreviousMinute work with time zones other than the system’s?
No. The function uses the local system time of the machine running Power Query. To handle other time zones, convert your datetime values to UTC or the target zone first using DateTimeZone.ToLocal or DateTimeZone.SwitchZone.Does this function work in DirectQuery mode in Power BI?
No. DateTime.IsInPreviousMinute is an M function that runs during data transformation in the Power Query engine and cannot be evaluated in DirectQuery mode. Use DAX time intelligence functions like TODAY() or NOW() instead for DirectQuery scenarios.What if my data arrives with a delay? Will this function still work?
It will still evaluate against the current system time, not the data’s arrival time. If data from 10:00:10 arrives at 10:02:00 due to latency, it will be marked as false because the function compares to the moment of refresh, not when the data was generated.Can I use this function to compare two datetime columns?
No. DateTime.IsInPreviousMinute only accepts a single datetime value and compares it to the system’s current time. To compare two columns, use a custom column with subtraction logic, like[Col1] > [Col2] - #duration(0,0,1,0) to check if Col1 is within the last minute of Col2.