Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Calculate working time between 2 timestamp in difference day

Hello,  I'm newbie here please let me know if i miss anything.   I want to calculate working time (minute) between 2 timestamps but not count time if it not in working hour (9.00 - 18.00) the da...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

     

    I suggest you to try this code to create a calcualted column.

    Processing time (Min) = 
    VAR _DAYDIFF =
        DATEDIFF ( 'Table'[Time A], 'Table'[Time B], DAY )
    VAR _REST_MIN = ( 6 + 9 ) * 60
    VAR _STARTDATE =
        IF (
            TIMEVALUE ( 'Table'[Time A] ) < TIME ( 9, 0, 0 ),
            DATEVALUE ( 'Table'[Time A] ) + TIME ( 9, 0, 0 ),
            IF (
                TIMEVALUE ( 'Table'[Time A] ) > TIME ( 18, 0, 0 ),
                DATEVALUE ( 'Table'[Time A] ) + TIME ( 18, 0, 0 ),
                'Table'[Time A]
            )
        )
    VAR _ENDDATE =
        IF (
            TIMEVALUE ( 'Table'[Time B] ) < TIME ( 9, 0, 0 ),
            DATEVALUE ( 'Table'[Time B] ) + TIME ( 9, 0, 0 ),
            IF (
                TIMEVALUE ( 'Table'[Time B] ) > TIME ( 18, 0, 0 ),
                DATEVALUE ( 'Table'[Time B] ) + TIME ( 18, 0, 0 ),
                'Table'[Time B]
            )
        )
    VAR _PROCESSTIME1 =
        DATEDIFF ( _STARTDATE, _ENDDATE, MINUTE )
    RETURN
        _PROCESSTIME1 - _REST_MIN * _DAYDIFF

    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.