Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreShape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.
Hi All.
I have a set of events where each line is either an On or Off event and I need to put the time stamp of each event in own column on the same row. The conditions are for each row with ON Value to find the next OFF value event and add that to a new column. Then remove all rows with off values.
Orginal Data
Time | Type | OD Comment | FN name | Entity | Value | Username |
11:21:40 08-May-2024 | Event | Straddle K7 | SYSTEM | O18005510/DI0 | OFF (0) | |
11:20:27 08-May-2024 | Event | Straddle K7 | SYSTEM | O18005510/DI0 | ON (1) | |
11:20:26 08-May-2024 | Event | Straddle K7 | SYSTEM | O18005510/DI0 | OFF (0) | |
11:20:25 08-May-2024 | Event | Straddle K7 | SYSTEM | O18005510/DI0 | ON (1) | |
11:19:19 08-May-2024 | Event | Straddle K7 | SYSTEM | O18005510/DI0 | OFF (0) | |
11:18:10 08-May-2024 | Event | Straddle K7 | SYSTEM | O18005510/DI0 | ON (1) | |
11:21:40 08-May-2024 | Event | Straddle K8 | SYSTEM | O18005510/DI0 | OFF (0) | |
11:20:27 08-May-2024 | Event | Straddle K8 | SYSTEM | O18005510/DI0 | ON (1) | |
11:20:26 08-May-2024 | Event | Straddle K8 | SYSTEM | O18005510/DI0 | OFF (0) | |
11:20:25 08-May-2024 | Event | Straddle K8 | SYSTEM | O18005510/DI0 | ON (1) | |
11:19:19 08-May-2024 | Event | Straddle K8 | SYSTEM | O18005510/DI0 | OFF (0) | |
11:18:10 08-May-2024 | Event | Straddle K8 | SYSTEM | O18005510/DI0 | ON (1) |
Result
Type | OD Comment | FN name | Entity | On Time | Off Time | Username |
Event | Straddle K7 | SYSTEM | O18005510/DI0 | 11:20:27 08-May-2024 | 11:21:40 08-May-2024 | |
Event | Straddle K7 | SYSTEM | O18005510/DI0 | 11:20:25 08-May-2024 | 11:20:26 08-May-2024 | |
Event | Straddle K7 | SYSTEM | O18005510/DI0 | 11:18:10 08-May-2024 | 11:19:19 08-May-2024 | |
Event | Straddle K8 | SYSTEM | O18005510/DI0 | 11:20:27 08-May-2024 | 11:21:40 08-May-2024 | |
Event | Straddle K8 | SYSTEM | O18005510/DI0 | 11:20:25 08-May-2024 | 11:20:26 08-May-2024 | |
Event | Straddle K8 | SYSTEM | O18005510/DI0 | 11:18:10 08-May-2024 | 11:19:19 08-May-2024 |
Thanks for your help
Solved! Go to Solution.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjS0MjK0MjFQMLDQ9U2s1DUyMDJR0lFyLUvNKwHSwSVFiSkpOakK3uYgXmRwiKsvkOFvaGFgYGpqaKDv4mkA4ru5KWgYaAJZCkqxOhBTDayMzCk01U9BwxDDUDOaONWU2k41tAQiqjvV0MLKkNK4wgxVohKABU0SAH5TyUwA5DiVcAIg0anEJQBSnUpcAiDaqbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t, Type = _t, #"OD Comment" = _t, #"FN name" = _t, Entity = _t, Value = _t, Username = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type datetime}, {"Type", type text}, {"OD Comment", type text}, {"FN name", type text}, {"Entity", type text}, {"Value", type text}, {"Username", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Replaced Value" = Table.ReplaceValue(#"Added Index",each [Index],each Number.RoundDown([Index]/2),Replacer.ReplaceValue,{"Index"}),
#"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[Value]), "Value", "Time"),
#"Removed Other Columns" = Table.SelectColumns(#"Pivoted Column",{"Type", "OD Comment", "FN name", "Entity", "Username", "OFF (0)", "ON (1)"})
in
#"Removed Other Columns"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
You could use Text.End in Power Query to extract the last characters of the column to create an ON/OFF column
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjS0MjK0MjFQMLDQ9U2s1DUyMDJR0lFyLUvNKwHSwSVFiSkpOakK3uYgXmRwiKsvkOFvaGFgYGpqaKDv4mkA4ru5KWgYaAJZCkqxOhBTDayMzCk01U9BwxDDUDOaONWU2k41tAQiqjvV0MLKkNK4wgxVohKABU0SAH5TyUwA5DiVcAIg0anEJQBSnUpcAiDaqbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t, Type = _t, #"OD Comment" = _t, #"FN name" = _t, Entity = _t, Value = _t, Username = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type datetime}, {"Type", type text}, {"OD Comment", type text}, {"FN name", type text}, {"Entity", type text}, {"Value", type text}, {"Username", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Replaced Value" = Table.ReplaceValue(#"Added Index",each [Index],each Number.RoundDown([Index]/2),Replacer.ReplaceValue,{"Index"}),
#"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[Value]), "Value", "Time"),
#"Removed Other Columns" = Table.SelectColumns(#"Pivoted Column",{"Type", "OD Comment", "FN name", "Entity", "Username", "OFF (0)", "ON (1)"})
in
#"Removed Other Columns"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
Thanks for the response. This worked perfectly, now I need to understand what you've provided.
User | Count |
---|---|
94 | |
92 | |
85 | |
83 | |
49 |
User | Count |
---|---|
150 | |
146 | |
112 | |
73 | |
56 |