March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
134 | |
91 | |
89 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
72 | |
68 |