Time.Minute

D

T

The M Code Behind the Power Query M function Time.Minute

One of the most commonly used functions in Power Query is the Time.Minute function. This function is used to extract the minute component from a given time value. In this article, we will take a closer look at the M code behind this function and explore some practical examples of how it can be used.

Understanding the Time.Minute Function

Before we dive into the M code behind the Time.Minute function, let’s first take a closer look at how this function works. The Time.Minute function takes a time value as its input and returns the minute component of that time value. For example, if the input time value is 3:15 PM, the Time.Minute function will return 15.

Here is the basic syntax of the Time.Minute function:


Time.Minute(time as any) as any


The ‘time’ argument is the input time value that you want to extract the minute component from. This argument can be any valid time value, such as a text string or a datetime value.

The M Code Behind Time.Minute

Now that we have a basic understanding of how the Time.Minute function works, let’s take a closer look at the M code behind this function. Here is the M code that is used to define the Time.Minute function:


(Time) =>

Duration.Minutes(Time.TimeOfDay)


This code defines a lambda function that takes a ‘Time’ argument and returns the minute component of that time value. The ‘Time.TimeOfDay’ property is used to extract the time component of the input ‘Time’ value, and the ‘Duration.Minutes’ function is used to extract the minute component from that time value.

Practical Examples of Time.Minute

Now that we understand the M code behind the Time.Minute function, let’s explore some practical examples of how this function can be used in Power Query.

Example 1: Extracting the Minute Component from a Time Value

Suppose you have a dataset that contains a column of time values, and you want to extract the minute component from each time value. Here is the M code that you can use to achieve this:


let

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ2VNJRMgoyMDJWCgVnYmNwCKlZKiqxNpY6SmpRYlGxamKmmqJxgYH3EYGRnZ6RsmAgA=", TextEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t]),

#"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type time}}),

#"Added Custom" = Table.AddColumn(#"Changed Type", "Minute", each Time.Minute([Time]))

in

#"Added Custom"


This code uses the ‘Table.FromRows’ function to create a table from the input data, and the ‘Table.TransformColumnTypes’ function to convert the ‘Time’ column to a time data type. The ‘Table.AddColumn’ function is then used to add a new column that contains the minute component of each time value.

Example 2: Filtering Rows Based on the Minute Component of a Time Value

Suppose you have a dataset that contains a column of time values, and you want to filter the dataset to only include rows where the minute component of the time value is greater than or equal to 30. Here is the M code that you can use to achieve this:


let

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ2VNJRMgoyMDJWCgVnYmNwCKlZKiqxNpY6SmpRYlGxamKmmqJxgYH3EYGRnZ6RsmAgA=", TextEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t]),

#"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type time}}),

#"Filtered Rows" = Table.SelectRows(#"Changed Type", each Time.Minute([Time]) >= 30)

in

#"Filtered Rows"


This code uses the ‘Table.FromRows’ function to create a table from the input data, and the ‘Table.TransformColumnTypes’ function to convert the ‘Time’ column to a time data type. The ‘Table.SelectRows’ function is then used to filter the table to only include rows where the minute component of the time value is greater than or equal to 30.

The Time.Minute function is a powerful tool that can be used to extract the minute component from a given time value in Power Query. By understanding the M code behind this function and exploring some practical examples of how it can be used, you can gain a better understanding of how to use this function to clean and transform 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)