let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"USER", type text}, {"TIME", type datetime}, {"STATUS", type text}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"USER", Order.Ascending}, {"TIME", Order.Ascending}}),
#"Filtered Rows - STATUS Opened" = Table.SelectRows(#"Sorted Rows", each ([STATUS] = "Opened")),
#"Added Opened Index" = Table.AddIndexColumn(#"Filtered Rows - STATUS Opened", "Opened Index", 1, 1, type text),
#"Renamed Column - Opened Time" = Table.RenameColumns(#"Added Opened Index",{{"TIME", "Opened Time"}}),
#"Filtered Rows - STATUS Closed" = Table.SelectRows(#"Sorted Rows", each ([STATUS] = "Closed")),
#"Added Closed Index" = Table.AddIndexColumn(#"Filtered Rows - STATUS Closed", "Closed Index", 1, 1, type text),
#"Renamed Column - Closed Time" = Table.RenameColumns(#"Added Closed Index",{{"TIME", "Closed Time"}}),
#"Merged Queries" = Table.NestedJoin(#"Renamed Column - Opened Time", {"Opened Index"}, #"Renamed Column - Closed Time", {"Closed Index"}, "Renamed Column - Closed Time", JoinKind.LeftOuter),
#"Expanded Renamed Column - Closed Time" = Table.ExpandTableColumn(#"Merged Queries", "Renamed Column - Closed Time", {"Closed Time"}, {"Closed Time"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Renamed Column - Closed Time",{"STATUS", "Opened Index"}),
#"Added Column - Duration" = Table.AddColumn(#"Removed Columns", "Duration", each [Closed Time] - [Opened Time], type duration)
in
#"Added Column - Duration"