DateTime.IsInPreviousSecond

Updated on

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

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

Syntax

DateTime.IsInPreviousSecond( dateTime as any ) as nullable logical

Description

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

Examples

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

Checking DateTime Values for the Previous Second

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 second. You can do this by using the DateTime.IsInPreviousSecond function on your [DateTime] column.

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

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

You might wonder what types of values can fall within the previous second. We’re talking about values that occur in the immediate previous second. For example, if the current time is 22:15:40.478 on July 7, 2024, this function will return true for all rows with DateTime values between 22:15:39.000 and 22:15:39.999.

Here’s a screenshot showing this:

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

As you can see, there are several values that fall within the previous second. Although the default DateTime value does not display fractional seconds, you can view the detailed values in the [DateTime Text] column, which uses a format string that includes fractional seconds.

Using the Current Date and Time

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

// Output: true
DateTime.IsInPreviousSecond( DateTime.FixedLocalNow() - #duration( 0, 0, 0, 0.25 ) )

Other functions related to DateTime.IsInPreviousSecond are:

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

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