What is the DURATION function?
The DURATION function is a date and time function in DAX that calculates the difference between two dates or times in a duration format. It is used to calculate the duration of an event, the time between two events, or the age of a person.
The syntax for the DURATION function is:
The time parameter can be a column or a scalar value that represents a time duration. The result of the DURATION function is always a duration value.
How does the DURATION function work?
The DURATION function works by subtracting the start time from the end time and returning the result in a duration format. The duration format is a decimal value that represents the number of days and fractions of a day between two times.
For example, if you want to calculate the duration between two dates, you can use the following formula:
DURATION([End Date] – [Start Date])
This will return the duration between the two dates in a decimal format.
How to use the DURATION function in Power BI
To use the DURATION function in Power BI, you need to follow these steps:
Step 1: Create a table with the start and end times
The first step is to create a table that contains the start and end times of the event you want to calculate the duration for. You can do this by importing a table from an external data source or creating a new table in Power BI.
Step 2: Create a new column with the DURATION function
Next, you need to create a new column in the table that uses the DURATION function to calculate the duration between the start and end times. You can do this by adding a new column to the table and using the following formula:
DURATION([End Time] – [Start Time])
Make sure to replace [End Time] and [Start Time] with the actual column names for the start and end times.
Step 3: Add the new column to your report
Once you have created the new column, you can add it to your Power BI report. You can do this by dragging and dropping the column onto the report canvas or adding it to a table or chart.
Step 4: Format the new column
Finally, you need to format the new column to display the duration in a readable format. You can do this by selecting the column in the Fields pane and selecting the duration format from the drop-down menu.
The DURATION function in DAX is a powerful tool that can help you calculate the duration between two dates or times in a decimal format. By following the steps outlined in this article, you can easily use the DURATION function in your Power BI reports to efficiently manage your data.
Power BI DAX Training Courses by G Com Solutions (0800 998 9248)
Power BI DAX Intensive Training Course£1,050.00 – £26,550.00
Power BI DAX Introduction£395.00 – £9,750.00
Power BI DAX Intermediate£395.00 – £9,750.00
Power BI DAX Advanced£395.00 – £9,750.00