Forum Discussion

niro53's avatar
niro53
Regular Visitor
3 years ago
Solved

Measure a work shift based on multiple datetime values

Hi community,  I have been trying to create a formula using DAX that would calculate working shift hours based on "Index". The work shift starts when the first order is taken(Order Start) and ends w...
  • amitchandak's avatar
    3 years ago

    niro53 , Try like

     

    AR _orderDifference = DATEDIFF('Taxi Bolt'[Order DateTime Start], 'Taxi Bolt'[Order DateTime End],MINUTE)
    VAR _lastDateTime =
    CALCULATE(MAX( 'Taxi Bolt'[Order DateTime End] ),
    FILTER(
    'Taxi Bolt',
    [Order DateTime End]< EARLIER([Order DateTime End])&&
    'Taxi Bolt'[Index]=EARLIER([Index])
    ))
    VAR _betweenOrdersTime = DATEDIFF(_nextDateTime, 'Taxi Bolt'[Order DateTime Start],MINUTE)
    VAR _total = _orderDifference + _betweenOrdersTime
    return IF(_betweenOrdersTime > 120 , 0, _total )