DateTime.IsInNextNMinutes

Updated on

DateTime.IsInNextNMinutes is a Power Query M function that indicates whether the provided date(time) value occurs during the next 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.IsInNextNMinutes(
   dateTime as any,
   minutes as number,
) as nullable logical

Description

DateTime.IsInNextNMinutes indicates whether the given dateTime argument (which can be of type datetime or datetimezone) occurs during the next 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.IsInNextNMinutes function works.

Checking DateTime Values for the Next 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 next n minutes. You can do this by using the DateTime.IsInNextNMinutes function on your [DateTime] column, where n is the number of minutes you want to check.

DateTime.IsInNextNMinutes( [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 next n minutes.

You might wonder what types of values can fall within the next few minutes. We’re talking about values that occur in the immediate future, within the specified range of minutes. For example, if you set n to 3, you would use the following code:

DateTime.IsInNextNMinutes( [DateTime], 3 )

If the current time is 10:22:10 on July 8, 2024, this function will return true for all rows with DateTime values between 10:23:00 and 10:25:59. Here’s a screenshot showing this:

Example of how to use the DateTime.IsInNextNMinutes Function in Power Query M

As the image shows, there are several values that fall within the next n minutes.

Using the Current Date and Time

If you want to check with DateTime.IsInNextNMinutes if the current date and time falls within the next few minutes, you can do that using the DateTime.FixedLocalNow function and adding a number of minutes using the #duration function:

// Output: true
DateTime.IsInNextNMinutes(
  DateTime.FixedLocalNow() + #duration(0, 0, 5, 0), 
  5
)

Other functions related to DateTime.IsInNextNMinutes are:

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

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