DateTime.IsInPreviousHour

Updated on

DateTime.IsInPreviousHour is a Power Query M function that indicates whether the provided date(time) value occurs during the previous hour. The function returns true if the value occurs in the previous hour, otherwise false.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

DateTime.IsInPreviousHour( dateTime as any ) as nullable logical

Description

DateTime.IsInPreviousHour indicates whether the given dateTime argument (which can be of type datetime or datetimezone) occurs during the previous hour, as determined by the current date and time on the system. This function will return false for a value within the current hour.

Examples

Let’s explore two examples to understand how the DateTime.IsInPreviousHour function works.

Checking DateTime Values for the Previous Hour

Suppose you have a table with DateTime values and you want to add a column that shows true for DateTime values that fall within the previous hour. You can do this by using the DateTime.IsInPreviousHour function on your [DateTime] column.

DateTime.IsInPreviousHour( [DateTime] ) // Output depends on [DateTime] column

This expression returns true for any DateTime values in the [DateTime] column that fall within the previous hour.

If the current time is 10:30:14 PM on July 7, 2024, this function will return true for all rows with DateTime values between 9:00:00 PM and 9:59:59 PM.

Here’s a screenshot to illustrate how the DateTime.IsInPreviousHour function works with a DateTime table:

How to use the DateTime.IsInPreviousHour Function in Power Query M

In this example, the DateTime values increment by fifteen minutes for each row. The column IsInPreviousHour shows true for DateTime values that fall within the previous hour.

Using the Current Date and Time

If you want to check with DateTime.IsInPreviousHour if the current date and time falls within the previous hour, you can do that using the DateTime.FixedLocalNow function and subtracting one hour using the #duration function:

// Output: true for the previous hour
DateTime.IsInPreviousHour(
  DateTime.FixedLocalNow() - #duration(0, 1, 0, 0)
)

Other functions related to DateTime.IsInPreviousHour are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/datetime-isinprevioushour

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy