Skip to content
Advertisement

Determine time duration based on events without using loops

I have a table with timestamps of 5 different types of events (start, stopped, restart, aborted, and completed). The given table looks like this:

Time EventID Event
7:38:20 1 start
7:40:20 2 stopped
7:48:20 3 restart
7:50:20 4 aborted
8:00:20 1 start
8:40:20 5 completed
8:58:20 1 start
9:00:15 4 aborted

I would like to determine the following and display it:

  • Duration of individual Wash –> From (start or restart) to (stopped or aborted or completed)
  • Duration of Wash Cycle –> From (start) to (aborted or completed)
  • Duration of total wash time –> Sum of all individual wash in a Wash cycle
  • Duration of idle time –> Wash Cycle duration – total wash time duration

So the table should look something like the following:

Time EventID Event Duration of individual Wash Duration of Wash Cycle Duration of total wash time Duration of idle time
7:38:20 1 start 0:02:00 0:12:00 0:04:00 0:08:00
7:40:20 2 stopped NULL NULL NULL NULL
7:48:20 3 restart 0:02:00 NULL NULL NULL
7:50:20 4 aborted NULL NULL NULL NULL
8:00:20 1 start 0:40:00 0:40:00 0:01:55 0:00:00
8:40:20 5 completed NULL NULL NULL NULL
8:58:20 1 start 0:01:55 0:01:55 0:01:55 0:00:00
9:00:15 4 aborted NULL NULL NULL NULL

So far I was able to get the duration of individual Wash and the duration of Wash Cycle by joining two table (one with only start, abort, and complete; the other with all events). I am stuck on the last two columns. I’m not sure how to approach this problem efficiently without using a while loop or counter of some sort. Would love some pointers.

Here are my code so far:

Advertisement

Answer

Try this example based on precalculating cycles IDs CycleStartId and CycleRestartId:

Here the reports are shown in seconds. If you need to format them as time, then you can use the following expression:

fiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement