Duration.Seconds is a Power Query M function that extracts the seconds portion of a duration value. The function returns an integer representing the number of seconds.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Duration.Seconds( duration as nullable duration ) as nullable number
Description
The Duration.Seconds function extracts the seconds portion (0-59) from a duration.
Examples
Let’s see how we can use the Time.Seconds function.
Extracting Seconds from a Time Value
The Duration.Seconds function extracts the number of seconds from a duration value. For example, a duration of 45 seconds returns 45 seconds:
Duration.Seconds( #duration( 0, 0, 0, 45 ) ) // Output: 45
The output is the same when the duration value specifies a combination of days, hours, minutes, and seconds. For instance, a duration of 1 minute and 30 seconds returns 30 seconds:
Duration.Seconds( #duration( 0, 0, 1, 30 ) ) // Output: 30
The output is also the same when the duration value specifies 90 seconds directly:
Duration.Seconds( #duration( 0, 0, 1, 90 ) ) // Output: 30
Creating a Time List
The Duration.Seconds function is particularly useful when generating a time list. Suppose you want to create a list of times every second starting from 12:00:00 PM and ending at 12:00:04 PM on the same day. You can use the following code:
List.Times(
#time( 12, 0, 0 ),
Duration.Seconds( #duration( 0, 0, 0, 4 ) ) + 1,
#duration( 0, 0, 0, 1 )
)
- List.Times: Generates a list of times.
- Start Time:
#time(12, 0, 0)specifies the starting time (12:00:00 PM). - Number of Seconds:
Duration.Seconds( #duration( 0, 0, 0, 4 ) ) + 1calculates the number of seconds in the duration. Adding 1 ensures the list includes both the start and end times. - Increment:
#duration( 0, 0, 0, 1 )specifies the interval between each time in the list (one second in this case).
By using Duration.Seconds, you can easily compute the number of seconds within a duration and generate a complete list of times for any given range.
Related functions
Other functions related to Duration.Seconds are:
2023-2026 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy