Duration.Seconds

D

T

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

Overview of Duration.Seconds function

The Duration.Seconds function is a built-in function in Power Query that calculates the duration between two dates or times in seconds. It takes two arguments: start and end, which are the starting and ending dates or times respectively. The function returns the duration in seconds as a decimal number.

Syntax of Duration.Seconds function

The syntax of the Duration.Seconds function is as follows:


Duration.Seconds(start as any, end as any) as any


The start and end arguments can be any data type that represents a valid date or time. The function returns a decimal number that represents the duration between the start and end arguments in seconds.

Example usage of Duration.Seconds function

Here is an example that demonstrates the usage of the Duration.Seconds function:


let

startDate = #datetime(2022, 1, 1, 0, 0, 0),

endDate = #datetime(2022, 1, 1, 0, 0, 10),

durationInSeconds = Duration.Seconds(startDate, endDate)

in

durationInSeconds


In this example, we define the start and end dates as #datetime values that represent January 1, 2022, at 12:00:00 AM and January 1, 2022, at 12:00:10 AM respectively. We then pass these values to the Duration.Seconds function, which calculates the duration between the two dates in seconds and returns the result as a decimal number (10).

The M code behind the Duration.Seconds function

The M code behind the Duration.Seconds function is relatively simple. The function is defined as follows:


(duration as duration) => Duration.TotalSeconds(duration)


The function takes a duration value as an argument and passes it to the Duration.TotalSeconds function, which calculates the total number of seconds in the duration value. The result is returned as a decimal number.

The Duration.Seconds function is a built-in function in Power Query that enables users to calculate the duration between two dates or times in seconds. The function is defined using the M language, which is a powerful tool that enables users to create custom functions and automate data transformation tasks. By understanding the M code behind the Duration.Seconds function, users can gain a deeper understanding of how Power Query works and how they can use it to transform and manipulate data in powerful ways.

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)