Forum Discussion
Duration in DAX
This was huge for me (and to learn about Variables in a DAX statement), but I struggled to get the blanks out for data rows which had no data - even after attribute filter was applied. This change at the end seemed to work in terms of setting it to no data (I'm not showing seconds) - but this has the behavior of null versus a blank for rows not qualified .. or this was showing up as blank - ".:"
- thanks for sharing!! And hopefully, my shorthand add helps someone else going down this road.
VAR H =
IF ( LEN ( Hours ) = 1,
CONCATENATE ( ".0", Hours ),
IF ( LEN ( Hours ) > 1,
CONCATENATE ( ".", Hours ), CONCATENATE ( "", Hours )
))
// Minutes with leading zeros
VAR M =
IF (
LEN ( Minutes ) = 1,
CONCATENATE ( ":0", Minutes ),
IF (
LEN ( Minutes ) > 1,
CONCATENATE ( ":", Minutes ), CONCATENATE ( "", Minutes )
))
// Now return hours, minutes and seconds with leading zeros in the proper format "hh:mm:ss"
RETURN
IF( Minutes > 0 , CONCATENATE (Days, CONCATENATE (H, M) ), Minutes )