вы можете попробовать что-то вроде следующего:
datatable(Id:int, Process:string, UpdateTime: datetime)
[
1, "Initiate", datetime(2020-02-02 12:00:00),
1, "Start", datetime(2020-02-02 13:00:00),
1, "End", datetime(2020-02-02 14:00:00),
2, "Initiate", datetime(2020-02-02 12:00:00),
2, "Start", datetime(2020-02-02 13:00:00),
3, "Initiate", datetime(2020-02-02 12:00:00),
3, "Start", datetime(2020-02-02 13:00:00),
3, "End", datetime(2020-02-02 14:00:00),
3, "Reopen", datetime(2020-02-02 15:00:00),
]
| order by Id asc, UpdateTime asc
| extend session_start = row_window_session(UpdateTime, 365d, 365d, Id != prev(Id))
| as hint.materialized = true T
| lookup (
T
| summarize arg_max(UpdateTime, Process) by session_start, Id
| project Id, LastProcess = Process
) on Id
| project Id, Process = case(LastProcess == "End", "Completed", "InProgress")
, что возвращает:
| Id | Process |
|----|------------|
| 1 | Completed |
| 1 | Completed |
| 1 | Completed |
| 2 | InProgress |
| 2 | InProgress |
| 3 | InProgress |
| 3 | InProgress |
| 3 | InProgress |
| 3 | InProgress |