DateTime.IsInPreviousNMinutes is a Power Query M function that indicates whether the provided date(time) value occurs during the previous number of minutes specified. The function returns true if the value occurs within the specified minutes, otherwise false.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
DateTime.IsInPreviousNMinutes(
dateTime as any,
minutes as number,
) as nullable logical
Description
DateTime.IsInPreviousNMinutes indicates whether the given dateTime
argument (which can be of type datetime or datetimezone) occurs during the previous number of minutes, as determined by the current date and time on the system. This function will return false for a value within the current minute.
Examples
Let’s explore two examples to understand how the DateTime.IsInPreviousNMinutes function works.
Checking DateTime Values for the Previous N Minutes
Imagine 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 n minutes. You can do this by using the DateTime.IsInPreviousNMinutes function on your [DateTime]
column, where n is the number of minutes you want to check.
DateTime.IsInPreviousNMinutes( [DateTime], n ) // Output depends on [DateTime] column and n
This expression returns true
for any DateTime values in the [DateTime]
column that fall within the previous n minutes. For example, if you set n to 3, you would use the following code:
DateTime.IsInPreviousNMinutes( [DateTime], 3 )
If the current time is 10:23:24 PM on July 7, 2024, this function will return true
for all rows with DateTime values between 10:20:00 PM and 10:22:59 PM. Here’s a screenshot that shows how this function can be used on a datetime table that increments with 1 second each row:
As the image shows, there are three values that fall within the previous 3 minutes.
Using the Current Date and Time
If you want to check with DateTime.IsInPreviousNMinutes if the current date and time falls within the previous few minutes, you can do that using the DateTime.FixedLocalNow function and subtracting a number of minutes using the #duration function:
// Output: true
DateTime.IsInPreviousNMinutes(
DateTime.FixedLocalNow() - #duration(0, 0, 5, 0),
5
)
Related functions
Other functions related to DateTime.IsInPreviousNMinutes are:
- DateTime.IsInPreviousHour
- DateTime.IsInPreviousMinute
- DateTime.IsInPreviousNHours
- DateTime.IsInPreviousNSeconds
- DateTime.IsInPreviousSecond
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy