Duration.TotalSeconds

Duration.TotalSeconds

D

The M Code Behind the Power Query M function Duration.TotalSeconds

What is the Duration.TotalSeconds function?

The Duration.TotalSeconds function is used to convert a duration value to a numeric value in seconds. This function takes a duration value as its input and returns a numeric value in seconds. The duration value can be a time span, a date/time value, or a duration value.

The M Code behind the Duration.TotalSeconds Function

The M code behind the Duration.TotalSeconds function is relatively simple. It involves the use of the Duration.TotalSeconds function and the Duration.From function, both of which are built-in functions in Power Query.

Here’s the M code for the Duration.TotalSeconds function:


(duration as duration) =>

Duration.TotalSeconds(duration)


As you can see, the function takes a single input parameter, which is the duration value that needs to be converted. This parameter is of the data type 'duration'.

The function then calls the built-in function Duration.TotalSeconds, passing the input parameter (duration) as an argument. The Duration.TotalSeconds function then returns a numeric value in seconds.

The Duration.TotalSeconds function is actually a simpler version of the Duration.ToText function, which is used to convert a duration value to a text value. The Duration.ToText function allows you to specify the format of the text value.

Here's the M code for the Duration.From function:


(seconds as number) =>

Duration.From(seconds)


The Duration.From function takes a single input parameter, which is the numeric value in seconds that needs to be converted to a duration value. This parameter is of the data type 'number'.

The function then calls the built-in function Duration.From, passing the input parameter (seconds) as an argument. The Duration.From function then returns a duration value.

Using the Duration.TotalSeconds function

The Duration.TotalSeconds function is often used in Power Query when working with duration values. For example, if you have a duration value that represents the length of a video clip, you can use the Duration.TotalSeconds function to convert it to a numeric value in seconds.

Here's an example of how to use the Duration.TotalSeconds function:


let

durationValue = #duration(0, 0, 3, 23),

secondsValue = Duration.TotalSeconds(durationValue)

in

secondsValue


In this example, we first define a duration value (durationValue) using the #duration function. This function takes four arguments, which are the number of days, hours, minutes, and seconds that make up the duration value.

We then call the Duration.TotalSeconds function, passing the durationValue as an argument. The function returns a numeric value in seconds, which is stored in the secondsValue variable.

The Duration.TotalSeconds function is a simple but powerful function in Power Query that allows you to convert a duration value to a numeric value in seconds. The M code behind this function is also simple, involving the use of two built-in functions in Power Query (Duration.TotalSeconds and Duration.From). By understanding how this function works and how to use it in Power Query, you can simplify your data transformation tasks and work more efficiently.

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)

Copyright, G Com Solutions Ltd, 2024.
Tower Bridge Business Centre, 46-48 East Smithfield, London E1W 1AW
0800 998 9248   |   9:00 a.m. till 5:30 p.m.

Connect With Me: