DateTime.IsInNextMinute

D

T

The M Code Behind the Power Query M function DateTime.IsInNextMinute

What is Power Query?

Before we dive in, let’s take a step back and talk about what Power Query is. Power Query is a data connection technology that allows you to extract data from various sources, transform that data into the format you need, and load it into your destination. It’s a part of the Microsoft Power BI suite, but it also comes built into Excel and can be used as a standalone tool.

Power Query uses a functional language called M to perform transformations on your data. M is a powerful and flexible language that allows you to write complex transformations with ease.

DateTime.IsInNextMinute

DateTime.IsInNextMinute is a function that checks whether a given datetime value is in the next minute. The function takes a single argument, which is the datetime value you want to check.

Here’s an example of how to use DateTime.IsInNextMinute:


let

dateTimeValue = #datetime(2022, 1, 1, 12, 34, 56),

result = DateTime.IsInNextMinute(dateTimeValue)

in

result


In this example, we're checking whether the datetime value `2022-01-01 12:34:56` is in the next minute. The result of this function call would be `true`, since the datetime value is in the next minute.

The M Code Behind DateTime.IsInNextMinute

Now that we've covered the basics of the DateTime.IsInNextMinute function, let's take a look at the M code behind it.


let

isDateTimeInNextMinute = (dateTimeValue as datetime) as logical =>

let

nextMinute = DateTime.AddMinutes(DateTime.LocalNow(), 1),

dateTimeValueMinute = DateTime.Minute(dateTimeValue),

nextMinuteMinute = DateTime.Minute(nextMinute),

dateTimeValueSecond = DateTime.Second(dateTimeValue),

nextMinuteSecond = DateTime.Second(nextMinute)

in

dateTimeValueMinute = nextMinuteMinute and dateTimeValueSecond < nextMinuteSecond

in

isDateTimeInNextMinute


This M code defines a function called `isDateTimeInNextMinute`. This function takes a single argument, which is the datetime value you want to check.

The function first calculates the datetime value of the next minute using the `DateTime.AddMinutes` function. It then extracts the minute and second values from the input datetime value and the next minute datetime value using the `DateTime.Minute` and `DateTime.Second` functions.

Finally, the function checks whether the minute value of the input datetime value is the same as the minute value of the next minute datetime value, and whether the second value of the input datetime value is less than the second value of the next minute datetime value. If both of these conditions are true, the function returns `true`, indicating that the input datetime value is in the next minute.

In conclusion, the DateTime.IsInNextMinute function is a powerful tool that allows you to check whether a given datetime value is in the next minute. The M code behind this function is relatively simple, but it demonstrates the power and flexibility of the M language.

If you're working with Power Query, it's essential to understand the underlying M code that powers the functions you're using. By understanding the M code behind DateTime.IsInNextMinute, you'll be better equipped to write your own custom functions and perform more complex transformations on your data.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)