Smart Systems for Home

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

Power Query DateTime.IsInNextHour: How to Use It

· 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

DateTime.IsInNextHour is a Power Query M function that returns true if a given datetime value falls within the next hour from the current moment. It does not look at the date alone or the hour number alone; it compares the full timestamp against the rolling window that starts now and ends one hour later. You use it in a custom column or a filter step when you want to flag records that are due in the coming hour, such as upcoming appointments, dispatch windows, or time-sensitive alerts. The function takes one argument, a datetime value, and returns a logical true or false. It is not a scheduling tool and it does not refresh itself; the result is calculated only when the query runs.

What You'll Need

  • Power Query Editor available in Excel, Power BI Desktop, or an equivalent host that supports M queries.
  • A table with a column that is already typed as Date/Time, or a way to combine separate date and time columns into a datetime value.
  • A basic understanding of how to add a custom column or edit a filter step in the Power Query Editor.
  • Awareness that the function evaluates against the current system time at refresh, not a fixed clock you set.

Step-by-Step

  1. Load your data into Power Query Editor. In Excel, select your table and choose Data > From Table/Range. In Power BI Desktop, choose Home > Transform data to open the editor. Menu labels can differ slightly by version, host, and region, so look for the equivalent command if the exact wording is not present.
  2. Confirm the column you want to test is a proper datetime type. Select the column, then on the Home tab use the data type dropdown and choose Date/Time. If the column is text, Power Query will not compare it correctly and the function will return an error or unexpected results.
  3. If your source stores date and time in separate columns, combine them first. Select the date column, then hold Ctrl and select the time column, and use Add Column > Merge Columns with a space separator. Then set the merged column's data type to Date/Time.
  4. Add a custom column for the test. On the Add Column tab, choose Custom Column. Give it a name such as InNextHour. In the formula box, enter the function with your datetime column as the argument, for example: DateTime.IsInNextHour([AppointmentTime]). The column name must match your actual column and is case-sensitive in the formula bar.
  5. Click OK. Power Query evaluates the function for each row and returns true or false. Review the new column to confirm the results make sense against a few known timestamps.
  6. Use the result. To keep only upcoming records, select the new column, open the filter dropdown, and clear all values except true. To keep the full table and just flag records, leave the column in place and load it to your destination.
  7. Load the query. In Excel, choose Home > Close & Load. In Power BI Desktop, choose Home > Close & Apply. The true or false values are now stored in the output table as they were at the moment of refresh.

Common Mistakes

The most frequent mistake is passing a date-only value. DateTime.IsInNextHour expects a datetime; if the column is typed as Date, the comparison may fail or produce an error. Convert the column to Date/Time first, or combine it with a time value. Another common error is assuming the function returns a static result. It evaluates at refresh time, so a query loaded yesterday will not update until it is refreshed again. A third mistake is using the function inside a filter step without checking the column type; Power Query may silently coerce values in ways that change the outcome. Also check for nulls: a null datetime argument returns null rather than true or false, which can affect downstream filters. Finally, do not confuse this function with DateTime.IsInCurrentHour, which tests the current hour rather than the next one; the two produce different results at the boundary.

Tips

Test the boundary behaviour with sample timestamps. A value exactly one hour from now may or may not be included depending on the exact implementation, so verify with a few rows around the edge. If you need a fixed window rather than a rolling one, calculate the window start and end as separate datetime values and compare with standard greater-than and less-than operators instead of using the built-in function. Keep a column with the refresh timestamp so you can audit why a row was flagged. When working with time zones, remember that the function uses the system time of the environment running the query, which may differ from the time zone of your data; convert timestamps to a common zone before testing. For recurring reports, document that the flag is refresh-dependent so consumers do not treat it as a permanent attribute.

Troubleshooting

If the custom column shows an error, check the column name in the formula and confirm the column is typed as Date/Time. If every row returns false, verify that your data actually contains timestamps within the next hour relative to the machine running the refresh; a common cause is a time zone mismatch between the data and the refresh environment. If the column returns null, inspect the source rows for blanks and decide whether to filter them out or replace them with a default. If the query is slow, the function itself is lightweight, so look for other steps such as merging or sorting that may be adding overhead. If results seem stale, refresh the query; the function does not recalculate on its own. If the function is not recognised, confirm you are using a host and version that supports it, and check that you have not mistyped the name, since M function names are case-sensitive.

Frequently Asked Questions

Does DateTime.IsInNextHour update automatically?

No. It is evaluated when the query refreshes, so the stored true or false values reflect the moment of the last refresh.

What is the difference between DateTime.IsInNextHour and DateTime.IsInCurrentHour?

IsInNextHour tests the rolling one-hour window starting now, while IsInCurrentHour tests the current clock hour. They can disagree near hour boundaries.

Can I use this function with a date-only column?

No. The argument must be a datetime value. Convert the column to Date/Time or combine it with a time column first.

Why do I get null instead of true or false?

A null datetime argument returns null. Check for blank values in the source column and handle them before applying the function.

Does the function use my local time zone?

It uses the system time of the environment running the query, which may not match your data's time zone. Convert timestamps to a common zone before testing.

Can I filter a table to only rows in the next hour?

Yes. Add the custom column, then filter it to true. Remember the filter is applied at refresh, not continuously.