Duration.Days is a Power Query M function that extracts the days portion of a duration value. The function returns an integer representing the number of days.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Duration.Days( duration as nullable duration ) as nullable number
Description
The Duration.Days function computes the number of whole days from a duration.
Examples
The Duration.Days function converts a duration value into the number of days it represents. For example, a duration of 48 hours returns two days:
Duration.Days( #duration( 0, 48, 0, 0 ) ) // Output 2
The output is the same when the duration value specifies two days instead of 48 hours:
Duration.Days( #duration( 2, 0, 0, 0 ) ) // Output 2
The Duration.Days function is particularly useful when generating a date table. Suppose you want to create a date table starting from January 1, 2024, and ending on December 31, 2024. You can use the following code:
List.Dates(
#date( 2024, 1, 1 ),
Duration.Days( #date( 2024, 12, 31 ) - #date( 2024, 1, 1 ) ) + 1,
#duration( 1, 0, 0, 0 )
)
- List.Dates: Generates a list of dates.Start Date:
#date(2024, 1, 1)specifies the starting date. - Number of Days:
Duration.Days(#date(2024, 12, 31) - #date(2024, 1, 1)) + 1calculates the number of days between the start and end dates. Adding 1 ensures the list includes both the start and end dates. - Increment:
#duration(1, 0, 0, 0)specifies the interval between each date in the list (one day in this case).
By using Duration.Days, you can easily compute the number of days between two dates.
Related articles
Learn more about Duration.Days in the following articles:
- Create ISO Week and ISO Year in Power Query M (ISO 8601)
Learn how to create ISO Week and Year numbers in Power Query for consistent weeks and fiscal calendars. Step-by-step tutorial included! » Read more - Create Date Table or Calendar in Power Query M
Learn how to create a dynamic calendar table in Power Query’s M language. Build your custom columns and claim your free Date Table Script. » Read more
Related functions
Other functions related to Duration.Days are:
2023-2026 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy