Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register 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!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
119 | |
83 | |
47 | |
42 | |
33 |
User | Count |
---|---|
190 | |
78 | |
72 | |
54 | |
45 |