Forum Discussion

rpinxt's avatar
rpinxt
Solution Sage
2 years ago
Solved

Rounding up time

I have these date/time staps and the duration between them :   Duration is a dax measure being : Duration = MAX(SC1[D&T]) - MAX(Sheet1[ATA])   The outcome is then formatted like (hh:nn:ss...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi rpinxt ,

     

    As far as I know, measure in time format like Duration = MAX(SC1[D&T]) - MAX(Sheet1[ATA]) has a limitation of 24 hour. So if your duration is 24:01:00, Power BI will only return 00:01:00.

    Here I suggest you to try DATEDIFF function.

    Flag = 
    VAR _HOURDIFF = DIVIDE(DATEDIFF(MAX(Sheet1[ATA]),MAX(SC1[D&T]),MINUTE),60)
    RETURN
    IF(_HOURDIFF>24,"Late","On Time")

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi rpinxt ,

     

    As far as I know, the time format data (like hh:mm:ss) in Power BI has the 24 hours limitation.

    If you want to show hh:mm:ss data outer 24 hours, I suggest you to try code as below.

    Please note that in this way your Duration will be in text data format.

    Duration New = 
    VAR _SECDIFF = DATEDIFF(MAX(Sheet1[ATA]),MAX(SC1[D&T]),SECOND)
    VAR _HOUR =INT(DIVIDE(_SECDIFF,3600))
    VAR _MIN = INT(DIVIDE(MOD(_SECDIFF,3600),60))
    VAR _SEC = _SECDIFF - _HOUR * 3600 - _MIN * 60
    RETURN
    COMBINEVALUES(":",FORMAT(_HOUR,"00"),FORMAT(_MIN,"00"),FORMAT(_SEC,"00"))

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.