Forum Discussion
Calculate Date Durations between 2 dates
- 1 year ago
Hi icassiem - your suggested method of using a calculated column for individual durations and a calculated measure for aggregation is correct.
using datediff. calculated column calculate duration days:
Duration_Days =
DATEDIFF(
TableName[StartDate],
TableName[EndDate],
DAY
)create a measure for total duration as
Total_Duration =
SUM(TableName[Duration_Days])Convert Duration to Hours or Mixed Format
Duration_Format =
VAR Days = INT(TableName[Duration_Hours] / 24)
VAR Hours = MOD(TableName[Duration_Hours], 24)
RETURN
Days & " days " & Hours & " hours"In your visual e.g., a table or matrix, add the "Stage" field to the rows.Add the Total_Duration measure to display the summed duration per stage.
Hi icassiem
Please try this:
Table:
Then add 2 calculated columns:
duration_Day =
ABS (
DATEDIFF ( 'Table'[HistoryClosedDateMax], 'Table'[HistoryCreatedDateMin], DAY )
)
duration_Hour =
ABS (
DATEDIFF ( 'Table'[HistoryClosedDateMax], 'Table'[HistoryCreatedDateMin], HOUR )
)
And 2 Measures:
_duration_Day =
ABS (
DATEDIFF (
MAX ( 'Table'[HistoryClosedDateMax] ),
MAX ( 'Table'[HistoryCreatedDateMin] ),
DAY
)
)
_duration_Hour =
ABS (
DATEDIFF (
MAX ( 'Table'[HistoryClosedDateMax] ),
MAX ( 'Table'[HistoryCreatedDateMin] ),
HOUR
)
)
The result is as follow:
Here for your reference:
DATEDIFF function (DAX) - DAX | Microsoft Learn
ABS function (DAX) - DAX | Microsoft Learn
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.