Hello @jamie.bryan,
Thank You for posting your query onto the Forum.
In order to achieve the results based on the scenario that you’ve mentioned. Below are the DAX measures alongwith the screenshot of the final results provided for the reference -
The solution is provided in a “Two-fold format” i.e., one in the form of “Text” format and other one in the form of “Numerical” format so that you can use the numerical one for adding the numbers or showcasing them in a graphical format, if required.
A). Text Format Measures -
1). Calculation of Basic Hours -
Basic Hours - Harsh =
VAR _Total_Seconds =
SUMX(
FILTER( Data ,
Data[HRSCODE] = "Basic Hours" ) ,
Data[MINUTES] ) * 60
VAR _Days =
TRUNC(
DIVIDE(
DIVIDE(
_Total_Seconds ,
3600 ,
0 ) ,
24 ,
0 ) )
VAR _Hours =
TRUNC(
DIVIDE(
_Total_Seconds - _Days * 3600 * 24 ,
3600 ,
0 ) )
VAR _Minutes =
TRUNC(
DIVIDE(
MOD(
_Total_Seconds , 3600 ) ,
60 ,
0 ) )
VAR _Seconds =
MOD(
_Total_Seconds , 60 )
VAR _Results =
IF( ISBLANK( _Total_Seconds ) ,
BLANK() ,
IF( _Days >= 1 , ( _Days * 24 ) + _Hours , _Hours ) & ":" &
IF( _Minutes < 10 , "0" & _Minutes , _Minutes ) & ":" &
IF( _Seconds < 10 , "0" & _Seconds , _Seconds ) )
RETURN
_Results
2). Calculation of O/T @ Time & Half -
O/T @ Time & Half - Harsh =
VAR _Total_Seconds =
SUMX(
FILTER( Data ,
Data[HRSCODE] = "O/T @ Time & Half" ) ,
Data[MINUTES] ) * 60
VAR _Days =
TRUNC(
DIVIDE(
DIVIDE(
_Total_Seconds ,
3600 ,
0 ) ,
24 ,
0 ) )
VAR _Hours =
TRUNC(
DIVIDE(
_Total_Seconds - _Days * 3600 * 24 ,
3600 ,
0 ) )
VAR _Minutes =
TRUNC(
DIVIDE(
MOD(
_Total_Seconds , 3600 ) ,
60 ,
0 ) )
VAR _Seconds =
MOD(
_Total_Seconds , 60 )
VAR _Results =
IF( ISBLANK( _Total_Seconds ) ,
BLANK() ,
IF( _Days >= 1 , ( _Days * 24 ) + _Hours , _Hours ) & ":" &
IF( _Minutes < 10 , "0" & _Minutes , _Minutes ) & ":" &
IF( _Seconds < 10 , "0" & _Seconds , _Seconds ) )
RETURN
_Results
B). Numerical Format Measures -
1). Calculation of Basic Hours -
Basic Hours - Hours - Harsh =
VAR _Total_Seconds =
SUMX(
FILTER( Data ,
Data[HRSCODE] = "Basic Hours" ) ,
Data[MINUTES] ) * 60
VAR _Days =
TRUNC(
DIVIDE(
DIVIDE(
_Total_Seconds ,
3600 ,
0 ) ,
24 ,
0 ) )
VAR _Hours =
TRUNC(
DIVIDE(
_Total_Seconds - _Days * 3600 * 24 ,
3600 ,
0 ) )
VAR _Minutes =
TRUNC(
DIVIDE(
MOD(
_Total_Seconds , 3600 ) ,
60 ,
0 ) )
VAR _Seconds =
MOD(
_Total_Seconds , 60 )
VAR _Results =
IF( ISBLANK( _Total_Seconds ) , BLANK() ,
IF( _Days < 1 , ( _Days * 24 ) + _Hours + ( _Minutes / 60 ) ,
IF( _Days >= 1 , ( _Days * 24 ) + _Hours + ( _Minutes / 60 ) ) ) )
RETURN
_Results
2). Calculation of O/T @ Time & Half -
O/T @ Time & Half - Hours - Harsh =
VAR _Total_Seconds =
SUMX(
FILTER( Data ,
Data[HRSCODE] = "O/T @ Time & Half" ) ,
Data[MINUTES] ) * 60
VAR _Days =
TRUNC(
DIVIDE(
DIVIDE(
_Total_Seconds ,
3600 ,
0 ) ,
24 ,
0 ) )
VAR _Hours =
TRUNC(
DIVIDE(
_Total_Seconds - _Days * 3600 * 24 ,
3600 ,
0 ) )
VAR _Minutes =
TRUNC(
DIVIDE(
MOD(
_Total_Seconds , 3600 ) ,
60 ,
0 ) )
VAR _Seconds =
MOD(
_Total_Seconds , 60 )
VAR _Results =
IF( ISBLANK( _Total_Seconds ) , BLANK() ,
IF( _Days < 1 , ( _Days * 24 ) + _Hours + ( _Minutes / 60 ) ,
IF( _Days >= 1 , ( _Days * 24 ) + _Hours + ( _Minutes / 60 ) ) ) )
RETURN
_Results
I’m also attaching the working of the PBIX file as well as providing a link of a post where I had provided a similar solution few days back.
Hoping you find this useful and meets your requirements that you’ve been looking for.
Thanks and Warm Regards,
Harsh
Time in HH:MM Format and Sub-Totals - Harsh.pbix (64.6 KB)
https://forum.enterprisedna.co/t/time-duration-is-not-adding-correctly/30220/2