Suppose I have the following table:
Table A: Event Log
ID Step WeekArrived WeekCompleted
-------------------------------------------------------
1 A 1 1
1 B 1 3
2 B 3 3
So in week 1, case 1 arrives. For this case, step A is completed in week 1, but step B is not. Step B is completed in week 3. Case 2 also arrives in week 3, and step B is completed in the same week (Step A wasn't needed for this case).
I would like to aggregate this event log into a weekly per step overview like this:
Table B: Weekly Overview
Week Step In Backlog Out
------------------------------------------------------------------
1 A 1 0 1
1 B 1 1 0
2 A 0 0 0
2 B 0 1 0
3 A 0 0 0
3 B 1 0 2
For each week X and step Y, this table shows:
- In: the number of cases that started step Y in week X
- Backlog: the number of cases which arrived at step Y in week <= X, and are not yet completed at the end of week X.
- Out: the number of cases that completed step Y in week X
How can I get from table A to table B?