
I am trying to analyze the difference between when the bus arrived at a stop vs the scheduled time and determine if the bus is early, late or ontime.
Here are the assumptions i am using for the calculation:
- Except for the last stop/column (where difference is measured using arrival time), the difference is calculated based on departure times from the stop. I am using MIN/MAX on the field [SORT ORDER] to determine the first/last stop
- Bus is considered to be late if difference is less than -5mins, on time if difference is between 0 and -5mins and early if it is greater than 0mins. This condition is different for the last stop where the bus is considered to be on time even if it arrives early.
The problem I am running into is on the last column where the schedule adherence is determined correctly for certain trips and wrong for some. Below is the calculation I am using to determine if the bus is early, late or ontime:
IF
AVG(IF {FIXED [SERIAL NUMBER (RIDE CHECK DETAIL (Ridecheck Plus.RIDE CHECK DETAIL) 41EF9449EEDA4CFDB5B59ECA2EB0FC8A)],[Route Name],[Direction Name],[Trip Start Time],[Timepoint]: MIN([Sort Order])}=[Sort Order] THEN(DATEDIFF('second',[Time Actual Depart],[Time Scheduled]))/60
ELSEIF {FIXED [SERIAL NUMBER (RIDE CHECK DETAIL (Ridecheck Plus.RIDE CHECK DETAIL) 41EF9449EEDA4CFDB5B59ECA2EB0FC8A)],[Route Name],[Direction Name],[Trip Start Time],[Timepoint]: MAX([Sort Order])}=[Sort Order] THEN(DATEDIFF('second',[Time Actual Arrive],[Time Scheduled]))/60
ELSE (DATEDIFF('second',[Time Actual Depart],[Time Scheduled]))/60 END) < -5 Then 'Late'
ELSEIF
AVG(IF {FIXED [SERIAL NUMBER (RIDE CHECK DETAIL (Ridecheck Plus.RIDE CHECK DETAIL) 41EF9449EEDA4CFDB5B59ECA2EB0FC8A)],[Route Name],[Direction Name],[Trip Start Time],[Timepoint]: MIN([Sort Order])}=[Sort Order] THEN(DATEDIFF('second',[Time Actual Depart],[Time Scheduled]))/60
ELSE (DATEDIFF('second',[Time Actual Depart],[Time Scheduled]))/60 END) >0 Then 'Early'
ELSE 'Ontime'
END
Thank you so much in advance.
Hi @Pranjal Dixit , This is interesting question. I guess the problem can come from Sort Order with the last stop. You can try to check the logic in Sort Order again.