Spreadsheet: 832002d1686053971-calculate-difference-between-times-based-on-multiple-criteria-calculate-the-difference-between-times-based-on-criteria
Sheet: Sheet1

 | Trip Duration | Block | Trip | From | To | Start | End | In-S |  | EXPECTED RESULTS
 |  | 1 | 103 | ABA3 | KIT2 | 5:26:00 | 5:41:46 | 1
 |  | 2 | 105 | ABA3 | KIT2 | 5:37:00 | 5:52:46 | 1 |  |  | *Dynamically Calculate the time difference between the start time of trip and the start time of the next trip by the same block and In-S = 1 and the results shouldn't be affected if I changed the Sort in the data table
 |  | 1 | 108 | KIT2 | ADM2 | 5:48:00 | 6:34:27 | 1
 |  | 2 | 110 | KIT2 | ADM2 | 5:58:30 | 6:44:57 | 1 |  |  | For example
 |  | 1 | 133 | ADM1 | KIT2 | 6:47:21 | 7:34:37 | 1
 |  | 2 | 135 | ADM1 | KIT2 | 6:53:51 | 7:41:07 | 1 |  |  | 108 | KIT2 | ADM2 | 5:48:00 | 6:34:27 |  | Difference
 |  | 1 | 138 | KIT2 | ADM2 | 7:38:15 | 8:24:42 | 1 |  |  | 133 | ADM1 | KIT2 | 6:47:21 | 7:34:37
 |  | 2 | 140 | KIT2 | ADM2 | 7:44:45 | 8:31:12 | 1
 |  | 1 | 165 | ADM1 | KIT2 | 8:31:21 | 9:18:37 | 1
 |  | 2 | 167 | ADM1 | KIT2 | 8:37:51 | 9:25:07 | 1
 |  | 1 | 170 | KIT2 | ADM2 | 9:22:15 | 10:08:42 | 1
 |  | 2 | 172 | KIT2 | ADM2 | 9:28:45 | 10:15:12 | 1
 |  | 1 | 197 | ADM1 | KIT2 | 10:15:21 | 11:02:37 | 1
 |  | 2 | 199 | ADM1 | KIT2 | 10:21:51 | 11:09:07 | 1
 |  | 1 | 202 | KIT2 | ADM2 | 11:06:15 | 11:52:42 | 1
 |  | 2 | 204 | KIT2 | ADM2 | 11:12:45 | 11:59:12 | 1
 |  | 1 | 229 | ADM1 | KIT2 | 11:59:21 | 12:46:37 | 1
 |  | 2 | 231 | ADM1 | KIT2 | 12:05:51 | 12:53:07 | 1
 |  | 1 | 234 | KIT2 | ADM2 | 12:50:15 | 13:36:42 | 1
 |  | 2 | 236 | KIT2 | ADM2 | 12:56:45 | 13:43:12 | 1
 |  | 1 | 263 | ADM1 | KIT2 | 13:48:21 | 14:35:37 | 1
 |  | 2 | 265 | ADM1 | KIT2 | 13:54:21 | 14:41:37 | 1
 |  | 1 | 268 | KIT2 | ADM2 | 14:38:15 | 15:24:42 | 1
 |  | 2 | 270 | KIT2 | ADM2 | 14:44:15 | 15:30:42 | 1
 |  | 1 | 301 | ADM1 | KIT2 | 15:34:21 | 16:21:37 | 1
 |  | 2 | 303 | ADM1 | KIT2 | 15:39:51 | 16:27:07 | 1
 |  | 1 | 306 | KIT2 | ADM2 | 16:24:15 | 17:10:42 | 1
 |  | 2 | 308 | KIT2 | ADM2 | 16:29:45 | 17:16:12 | 1
 |  | 1 | 339 | ADM1 | KIT2 | 17:18:51 | 18:06:07 | 1
 |  | 2 | 341 | ADM1 | KIT2 | 17:24:21 | 18:11:37 | 1
 |  | 1 | 344 | KIT2 | ADM2 | 18:08:45 | 18:55:12 | 1
 |  | 2 | 346 | KIT2 | ADM2 | 18:14:15 | 19:00:42 | 1
 |  | 1 | 377 | ADM1 | KIT2 | 19:03:21 | 19:50:37 | 1
 |  | 2 | 379 | ADM1 | KIT2 | 19:08:51 | 19:56:07 | 1
 |  | 1 | 382 | KIT2 | ADM2 | 19:53:15 | 20:39:42 | 1
 |  | 2 | 384 | KIT2 | ADM2 | 19:58:45 | 20:45:12 | 1
 |  | 1 | 415 | ADM1 | KIT2 | 20:47:51 | 21:35:07 | 1
 |  | 2 | 417 | ADM1 | KIT2 | 20:53:21 | 21:40:37 | 1
 |  | 1 | 420 | KIT2 | ADM2 | 21:37:45 | 22:24:12 | 1
 |  | 2 | 422 | KIT2 | ADM2 | 21:43:15 | 22:29:42 | 1
 |  | 1 | 453 | ADM1 | KIT2 | 22:32:21 | 23:19:37 | 1
 |  | 2 | 455 | ADM1 | KIT2 | 22:37:51 | 23:25:07 | 1
 |  | 1 | 458 | KIT2 | ADM2 | 23:22:15 | 1 day, 0:08:42 | 1
 |  | 2 | 460 | KIT2 | ADM2 | 23:27:45 | 1 day, 0:14:12 | 1
 |  | 1 | 485 | ADM1 | KIT2 | 1 day, 0:17:51 | 1 day, 1:05:07 | 1
 |  | 1 | 5282 | ADM2 | ADM5 | 8:25:40 | 8:27:07 | 0
 |  | 1 | 5283 | ADM5 | ADM1 | 8:27:47 | 8:29:14 | 0
 |  | 2 | 5316 | ADM2 | ADM5 | 6:45:55 | 6:47:22 | 0
 |  | 2 | 5317 | ADM5 | ADM1 | 6:48:02 | 6:49:29 | 0
 |  | 2 | 5318 | ADM2 | ADM5 | 8:32:10 | 8:33:37 | 0
 |  | 2 | 5319 | ADM5 | ADM1 | 8:34:17 | 8:35:44 | 0
 |  | 1 | 5442 | DTABA | ABA3 | 5:22:00 | 5:25:00 | 0
 |  | 2 | 5443 | DTABA | ABA3 | 5:33:00 | 5:36:00 | 0
 |  | 1 | 5446 | ADM2 | ADM5 | 6:37:25 | 6:38:52 | 0
 |  | 1 | 5447 | ADM5 | ADM1 | 6:43:22 | 6:44:49 | 0
 |  | 2 | 5704 | ADM2 | ADM5 | 15:31:40 | 15:33:07 | 0
 |  | 2 | 5705 | ADM5 | ADM1 | 15:34:47 | 15:36:14 | 0
 |  | 2 | 5706 | ADM2 | ADM5 | 17:17:10 | 17:18:37 | 0
 |  | 2 | 5707 | ADM5 | ADM1 | 17:19:17 | 17:20:44 | 0
 |  | 1 | 5768 | ADM2 | ADM5 | 15:25:40 | 15:27:07 | 0
 |  | 1 | 5769 | ADM5 | ADM1 | 15:29:47 | 15:31:14 | 0
 |  | 1 | 5770 | ADM2 | ADM5 | 17:11:40 | 17:13:07 | 0
 |  | 1 | 5771 | ADM5 | ADM1 | 17:13:47 | 17:15:14 | 0
 |  | 1 | 5868 | ADM2 | ADM5 | 20:40:40 | 20:42:07 | 0
 |  | 1 | 5869 | ADM5 | ADM1 | 20:42:47 | 20:44:14 | 0
 |  | 1 | 5979 | KIT2 | ABA3 | 1 day, 1:08:00 | 1 day, 1:20:46 | 0
 |  | 1 | 5981 | ABA3 | DTABA | 1 day, 1:23:46 | 1 day, 1:26:46 | 0
 |  | 2 | 5986 | ADM2 | ADM5 | 19:01:40 | 19:03:07 | 0
 |  | 2 | 5987 | ADM5 | ADM1 | 19:03:47 | 19:05:14 | 0
 |  | 1 | 6002 | ADM2 | ADM5 | 18:56:10 | 18:57:37 | 0
 |  | 1 | 6003 | ADM5 | ADM1 | 18:58:17 | 18:59:44 | 0
 |  | 1 | 6033 | ADM2 | ADM5 | 10:09:40 | 10:11:07 | 0
 |  | 1 | 6034 | ADM5 | ADM1 | 10:11:47 | 10:13:14 | 0
 |  | 2 | 6035 | ADM2 | ADM5 | 10:16:10 | 10:17:37 | 0
 |  | 2 | 6036 | ADM5 | ADM1 | 10:18:17 | 10:19:44 | 0
 |  | 2 | 6047 | ADM2 | ADM5 | 12:00:10 | 12:01:37 | 0
 |  | 2 | 6048 | ADM5 | ADM1 | 12:02:17 | 12:03:44 | 0
 |  | 1 | 6049 | ADM2 | ADM5 | 11:53:40 | 11:55:07 | 0
 |  | 1 | 6050 | ADM5 | ADM1 | 11:55:47 | 11:57:14 | 0
 |  | 1 | 6075 | ADM2 | ADM5 | 22:25:10 | 22:26:37 | 0
 |  | 1 | 6076 | ADM5 | ADM1 | 22:29:07 | 22:30:34 | 0
 |  | 2 | 6081 | ADM2 | ADM5 | 20:46:10 | 20:47:37 | 0
 |  | 2 | 6082 | ADM5 | ADM1 | 20:48:17 | 20:49:44 | 0
 |  | 2 | 6083 | ADM2 | ADM5 | 22:30:40 | 22:32:07 | 0
 |  | 2 | 6084 | ADM5 | ADM1 | 22:34:37 | 22:36:04 | 0
 |  | 1 | 6122 | ADM2 | ADM5 | 1 day, 0:09:40 | 1 day, 0:11:07 | 0
 |  | 1 | 6123 | ADM5 | ADM1 | 1 day, 0:13:37 | 1 day, 0:15:04 | 0
 |  | 2 | 6138 | ADM2 | DTSLM | 1 day, 0:15:12 | 1 day, 0:21:12 | 0
 |  | 1 | 6163 | ADM2 | ADM5 | 13:39:40 | 13:41:07 | 0
 |  | 1 | 6164 | ADM5 | ADM1 | 13:43:47 | 13:45:14 | 0
 |  | 2 | 6165 | ADM2 | ADM5 | 13:46:10 | 13:47:37 | 0
 |  | 2 | 6166 | ADM5 | ADM1 | 13:49:17 | 13:50:44 | 0