Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Detect Previous Job DropOff Time

Hi there, Hope you are doing well. I need help for the below. Duration (mins) is the column I need to create. Grouping by Driver ID, the blue highlighted are using [Drop Time] - [Accept Tim...
  • VahidDM's avatar
    VahidDM
    4 years ago

    Hi Anonymous 

     

    First add a new column with below code to rank the rows by Drop time:

    Rank =
    RANKX (
        FILTER ( 'Table', 'Table'[Driver ID] = EARLIER ( 'Table'[Driver ID] ) ),
        'Table'[Drop Time],
        ,
        ASC,
        DENSE
    )

    Then use below code to add a Duration (mins) column:

    Duration (mins) =
    VAR _Drop = 'Table'[Drop Time]
    VAR _DropRank = 'Table'[Rank]
    VAR _LDrop =
        CALCULATE (
            MAX ( 'Table'[Drop Time] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Rank] = ( _DropRank - 1 )
                    && 'Table'[Driver ID] = EARLIER ( 'Table'[Driver ID] )
            )
        )
    VAR _AT = 'Table'[Accept Time]
    RETURN
        IF (
            _AT > _LDrop,
            DATEDIFF ( _AT, _Drop, MINUTE ),
            DATEDIFF ( _LDrop, _Drop, MINUTE )
        )

     

    Output:

     

     

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

    Appreciate your Kudos✌️!!