Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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:
Solved! Go to Solution.
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.
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.
Refer, if these can help
https://community.powerbi.com/t5/Desktop/Converting-HH-MM-SS-to-seconds/m-p/674207
https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
64 |
User | Count |
---|---|
135 | |
122 | |
101 | |
71 | |
61 |