Smart Systems for Home

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

DateTime.IsInNextMinute Power Query 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 DateTime.IsInNextMinute function in Power Query returns a logical value (TRUE or FALSE) indicating whether a specific date-time value falls within the one-minute window immediately following the current system time. This is primarily used for real-time data monitoring, scheduling triggers, or filtering logs where you need to identify events that are slated to happen in the very next 60-second interval relative to the moment the query is refreshed.

What You'll Need

  • Microsoft Excel (with Power Query/Get & Transform) or Power BI Desktop.
  • A dataset containing a column with the DateTime data type.
  • Basic familiarity with the Power Query Editor interface.

Step-by-Step

  1. Load Your Data: Open Power BI Desktop or Excel. Go to the Data tab (Excel) or Home tab (Power BI) and select Get Data to import your source. Once the data is loaded into the Power Query Editor, ensure your target column is correctly typed. Right-click the column header, select Change Type, and choose DateTime. If the column is only a Date or only a Time, the function will return an error.
  2. Add a Custom Column: Navigate to the Add Column tab on the top ribbon. Click on Custom Column. This opens the Custom Column dialog box where you can write the M formula.
  3. Enter the Function: In the Custom column formula box, enter the following syntax: = DateTime.IsInNextMinute([YourColumnName]). Replace [YourColumnName] with the actual name of the column containing your timestamps. Note that Power Query is case-sensitive; ensure you capitalize the D, T, I, N, and M exactly as shown.
  4. Verify the Result: Click OK. A new column will appear containing TRUE or FALSE values. A TRUE value indicates that the timestamp in that row occurs within the next minute from the exact moment you clicked the refresh button.
  5. Filter the Data: If you only want to see the rows occurring in the next minute, click the filter dropdown arrow on the new custom column header and uncheck FALSE. This leaves only the records that meet the criteria.
  6. Clean Up: Once the filter is applied, you can right-click the custom column and select Remove. The filter step remains in the Applied Steps list, so the data will stay filtered even after the helper column is gone.
  7. Apply Changes: Click File > Close & Apply to bring the filtered results into your data model or Excel worksheet.

Common Mistakes

One of the most frequent errors is using the function on a column that is set to the Date or Time data type instead of DateTime. Because the function specifically looks for a combination of date and time to calculate the offset from the current system clock, providing only a date will cause a type mismatch error. Always verify the icon next to the column header shows the calendar-and-clock symbol.

Another common mistake is forgetting that Power Query is case-sensitive. Writing datetime.isinnextminute in lowercase will result in a "Token Literal expected" or "The name 'datetime.isinnextminute' wasn't recognized" error. The M language requires strict adherence to PascalCase for its built-in functions.

Users also often confuse this function with a static filter. Because DateTime.IsInNextMinute relies on the current system time (DateTime.LocalNow() internally), the results will change every time the query is refreshed. If you refresh the data at 10:00:05 AM, a record at 10:01:00 AM is TRUE. If you refresh again at 10:01:10 AM, that same record becomes FALSE because it is now in the past.

Tips

To make your query more robust, consider creating a parameter for your "current time" if you are testing data from a specific historical point. While DateTime.IsInNextMinute uses the system clock by default, you can perform similar logic using DateTime.LocalNow() combined with Duration.FromMinutes(1) if you need a custom window larger than one minute.

If you are working with data from different time zones, be cautious. Power Query's local functions use the time zone of the machine performing the refresh. If your server is in UTC but your users are in EST, the "Next Minute" calculation may be off by several hours. To fix this, convert your timestamps to the local time zone using DateTimeZone.ToLocal before applying the function.

For better performance on very large datasets, apply the DateTime.IsInNextMinute filter as early as possible in your Applied Steps. Filtering rows early reduces the amount of data that subsequent steps (like merges or complex transformations) have to process, which significantly speeds up the refresh time.

Troubleshooting

If the function returns an error, first check the data type of the column. If it says "Any" or "Text," the function will fail. Convert it to DateTime. If you see an error like "Expression.Error: We cannot convert the value null to type DateTime," it means you have null values in your timestamp column. To fix this, select the column, go to the Transform tab, and use Replace Values to replace nulls with a dummy date, or filter out the nulls before adding the custom column.

If the function returns FALSE for everything when you are certain there is data for the next minute, check your system clock. Ensure the computer running the query has the correct date and time settings. Additionally, check if your data source is providing timestamps in UTC while your system is in a local time zone; this discrepancy will make the records appear to be in the past or far future.

If the query is running slowly, check if you have "Enable Load" turned on for multiple intermediate queries. Using the function in a filtered view is efficient, but if you are creating multiple custom columns based on time calculations across millions of rows, it can strain memory. Try to combine your time logic into a single step using a let...in block in the Advanced Editor.

Frequently Asked Questions

Does this function include the current minute?

No. DateTime.IsInNextMinute specifically checks if the value is greater than the current time and less than the end of the next minute boundary. It does not include the minute currently in progress.

Can I use this for the next hour instead?

There is no DateTime.IsInNextHour function. To achieve this, you would subtract the current time from your timestamp and check if the resulting duration is between 0 and 60 minutes using Duration.TotalMinutes.

Will this work in a scheduled refresh in the Power BI Service?

Yes, but be aware that the Power BI Service uses UTC time for its cloud gateways and refresh engines. If your data is in a local time zone, you must adjust the timestamps to UTC or vice versa for the "Next Minute" logic to align correctly.

Is there a way to check for the previous minute?

Yes, Power Query provides a corresponding function called DateTime.IsInPreviousMinute, which works identically but looks at the 60-second window immediately preceding the current system time.

Does the function account for leap seconds?

Power Query handles date and time calculations based on standard Gregorian calendar logic and system clock intervals. It does not provide a specialized mechanism for leap seconds beyond what the underlying operating system's clock provides.

Can I use this function in a DAX calculated column instead?

No, DateTime.IsInNextMinute is an M function used in the Power Query Editor. For DAX, you would need to use a combination of NOW() and DATEADD or simple subtraction logic to determine if a date falls within the next minute.