Forum Discussion
Addition of time value.
Hi,
I have a column that has data stored in HH:MM: SS format.
I just need the cumulative / sum value of that column in Days:HH:MM: SS.
i tried dax function:
Hi Anonymous ,
Please check if this is what you want:
Case 1: Your time column is <24 hours and stored in "Time" type and "HH:MM:SS" format.
Create a measure like so:
Sum Measure <24 hours = VAR Seconds1 = SUMX ( 'Table', SECOND ( 'Table'[<24hours] ) ) VAR Minutes1 = SUMX ( 'Table', MINUTE ( 'Table'[<24hours] ) ) VAR Hours1 = SUMX ( 'Table', HOUR ( 'Table'[<24hours] ) ) VAR Seconds2 = MOD ( Seconds1, 60 ) VAR Minutes2 = MOD ( TRUNC ( Seconds1 / 60 ) + Minutes1, 60 ) VAR Hours2 = MOD ( Hours1 + TRUNC ( ( TRUNC ( Seconds1 / 60 ) + Minutes1 ) / 60 ), 24 ) VAR Days = TRUNC ( ( Hours1 + TRUNC ( ( TRUNC ( Seconds1 / 60 ) + Minutes1 ) / 60 ) ) / 24 ) RETURN FORMAT ( Days, "00" ) & ":" & FORMAT ( Hours2, "00" ) & ":" & FORMAT ( Minutes2, "00" ) & ":" & FORMAT ( Seconds2, "00" )Case 2: Your time column is >24 hours and stored in "Text" type and "Text" format.
Create a measure like so:
Sum Measure >24 hours = VAR Seconds1 = SUMX ( 'Table', CALCULATE ( VALUE ( RIGHT ( MAX ( 'Table'[>24hours] ), 2 ) ) ) ) VAR Minutes1 = SUMX ( 'Table', CALCULATE ( VALUE ( LEFT ( RIGHT ( MAX ( 'Table'[>24hours] ), 5 ), 2 ) ) ) ) VAR Hours1 = SUMX ( 'Table', CALCULATE ( VALUE ( LEFT ( MAX ( 'Table'[>24hours] ), 2 ) ) ) ) VAR Seconds2 = MOD ( Seconds1, 60 ) VAR Minutes2 = MOD ( TRUNC ( Seconds1 / 60 ) + Minutes1, 60 ) VAR Hours2 = MOD ( Hours1 + TRUNC ( ( TRUNC ( Seconds1 / 60 ) + Minutes1 ) / 60 ), 24 ) VAR Days = TRUNC ( ( Hours1 + TRUNC ( ( TRUNC ( Seconds1 / 60 ) + Minutes1 ) / 60 ) ) / 24 ) RETURN FORMAT ( Days, "00" ) & ":" & FORMAT ( Hours2, "00" ) & ":" & FORMAT ( Minutes2, "00" ) & ":" & FORMAT ( Seconds2, "00" )The results:
For more details, please check the attached PBIX file.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- AnonymousNot applicableHi amitchandak
I went through the links but still have doubts and confusions since I'm new to power bi.
Can you please help me by sending the Dax code for the same. It would be a huge help. Thanks
- Icey
Community Support
Hi Anonymous ,
Please check if this is what you want:
Case 1: Your time column is <24 hours and stored in "Time" type and "HH:MM:SS" format.
Create a measure like so:
Sum Measure <24 hours = VAR Seconds1 = SUMX ( 'Table', SECOND ( 'Table'[<24hours] ) ) VAR Minutes1 = SUMX ( 'Table', MINUTE ( 'Table'[<24hours] ) ) VAR Hours1 = SUMX ( 'Table', HOUR ( 'Table'[<24hours] ) ) VAR Seconds2 = MOD ( Seconds1, 60 ) VAR Minutes2 = MOD ( TRUNC ( Seconds1 / 60 ) + Minutes1, 60 ) VAR Hours2 = MOD ( Hours1 + TRUNC ( ( TRUNC ( Seconds1 / 60 ) + Minutes1 ) / 60 ), 24 ) VAR Days = TRUNC ( ( Hours1 + TRUNC ( ( TRUNC ( Seconds1 / 60 ) + Minutes1 ) / 60 ) ) / 24 ) RETURN FORMAT ( Days, "00" ) & ":" & FORMAT ( Hours2, "00" ) & ":" & FORMAT ( Minutes2, "00" ) & ":" & FORMAT ( Seconds2, "00" )Case 2: Your time column is >24 hours and stored in "Text" type and "Text" format.
Create a measure like so:
Sum Measure >24 hours = VAR Seconds1 = SUMX ( 'Table', CALCULATE ( VALUE ( RIGHT ( MAX ( 'Table'[>24hours] ), 2 ) ) ) ) VAR Minutes1 = SUMX ( 'Table', CALCULATE ( VALUE ( LEFT ( RIGHT ( MAX ( 'Table'[>24hours] ), 5 ), 2 ) ) ) ) VAR Hours1 = SUMX ( 'Table', CALCULATE ( VALUE ( LEFT ( MAX ( 'Table'[>24hours] ), 2 ) ) ) ) VAR Seconds2 = MOD ( Seconds1, 60 ) VAR Minutes2 = MOD ( TRUNC ( Seconds1 / 60 ) + Minutes1, 60 ) VAR Hours2 = MOD ( Hours1 + TRUNC ( ( TRUNC ( Seconds1 / 60 ) + Minutes1 ) / 60 ), 24 ) VAR Days = TRUNC ( ( Hours1 + TRUNC ( ( TRUNC ( Seconds1 / 60 ) + Minutes1 ) / 60 ) ) / 24 ) RETURN FORMAT ( Days, "00" ) & ":" & FORMAT ( Hours2, "00" ) & ":" & FORMAT ( Minutes2, "00" ) & ":" & FORMAT ( Seconds2, "00" )The results:
For more details, please check the attached PBIX file.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.