Duration.Days

Updated on

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)) + 1 calculates 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.

Learn more about Duration.Days in the following articles:

Other functions related to Duration.Days are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/duration-days

2023-2026 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy