I was wondering if I could get some help in terms of calculating a difference between the date of various statuses. I have a view with column named “id”, “create_dt” and “status”. I would have various statuses like submit, approve, deliver etc. Now, I want to find the time it took for a specific id between Approve and Submit status. What I am thinking currently is, creating few additional fields based on the status (I can use case statement for that) and finding the difference in time between the newly created date columns for various statuses. The problem here is, I am not sure how to drive the calculation based on the specific id. I can’t do lag or lead because some “id” might go through different statuses and some might not (it’s not consistent). I can’t create a the new date column based on id (something like partition by) because I am using case statement. Could someone point me to the right direction?
Below is the screenshot of how my data currently looks like (using the case statement) and what my desired output is. Current Result
From the expected result, I could easily find the difference between submitted and approved status for any ID using case statement whereas for the current result, I am not able to.
Thank you,