Forum Discussion
Comparing dates in adjacent rows
- 8 years ago
Using your dataset, I created 3 measures as below -
WorkingTime =
CALCULATE ( MINX( FILTER(ShiftData,ShiftData[Status]="Working"),ShiftData[Timestamp]) , ALLEXCEPT ( ShiftData, ShiftData[Job Ref] ) )
SuspendedTime =
CALCULATE ( MAXX( FILTER(ShiftData,ShiftData[Status]="Suspended"),ShiftData[Timestamp]) , ALLEXCEPT ( ShiftData, ShiftData[Job Ref] ) )
TotalTimeSpent = [SuspendedTime] - [WorkingTime]
Here is how the data looks -
Check and let me know if it helps you.
Regards
- brokencornets8 years agoHelper IV
Thanks for getting back to me vmakhija
Unfortunately it's not quite bring back the results I need, as it only brings back the working time and not the travelling time, and also doesn't take into account when jobs are completed, only suspended. It also only seems to look at one days worth of work, although that could be because it's only looking for suspended and not complete?
The ideal reasult I'm looking for is this:
Status Timestamp Activity Crew End Timestamp Travel 12/02/2018 09:33 22 John Doe 12/02/2018 09:34 Working 12/02/2018 09:34 22 John Doe 12/02/2018 15:58 Suspended 12/02/2018 15:58 22 John Doe null Travel 13/02/2018 07:55 3 John Doe 13/02/2018 07:59 Working 13/02/2018 07:59 3 John Doe 13/02/2018 15:46 Suspended 13/02/2018 15:46 3 John Doe null Travel 14/02/2018 08:20 22 John Doe 14/02/2018 08:20 Working 14/02/2018 08:20 22 John Doe 14/02/2018 11:44 Complete 14/02/2018 11:44 22 John Doe null - Zubair_Muhammad8 years agoCommunity Champion
Try this. First Add an Index Column in your Table using Query Editor
Then use this calculated column
Column = VAR NextTimeSTamp = CALCULATE ( MIN ( Table1[Timestamp] ), FILTER ( ALLEXCEPT ( Table1, Table1[Crew] ), Table1[Index] > EARLIER ( Table1[Index] ) ) ) VAR NextJobRef = CALCULATE ( MIN ( Table1[Job Ref] ), FILTER ( ALLEXCEPT ( Table1, Table1[Crew] ), Table1[Timestamp] = NextTimeSTamp ) ) RETURN IF ( Table1[Job Ref] = NextJobRef, NextTimeSTamp )- Zubair_Muhammad8 years agoCommunity Champion