I have a table like so:
ID Timestamp Status
A 5/30/2022 2:29 Run Ended
A 5/30/2022 0:23 In Progress
A 5/30/2022 0:22 Prepared
B 5/30/2022 11:15 Run Ended
B 5/30/2022 9:18 In Progress
B 5/30/2022 0:55 Prepared
I want to compute the duration between each status grouped by the ID. So the resulting output table would be:
ID Duration(min) Status change
A 0.40 In Progress-Prepared
A 125.82 Run Ended - In Progress
B 502.78 In Progress-Prepared
B 117.34 Run Ended - In Progress
How do I order it by descending timestamp (grouped by ID) and then subtract the last row from the previous row all the way upto the top for each ID group?