Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Phill360
New Member

Refer to another row with multiple conditions

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

TimeTypeOD CommentFN nameEntityValueUsername
11:21:40 08-May-2024EventStraddle K7SYSTEMO18005510/DI0OFF (0) 
11:20:27 08-May-2024EventStraddle K7SYSTEMO18005510/DI0ON (1) 
11:20:26 08-May-2024EventStraddle K7SYSTEMO18005510/DI0OFF (0) 
11:20:25 08-May-2024EventStraddle K7SYSTEMO18005510/DI0ON (1) 
11:19:19 08-May-2024EventStraddle K7SYSTEMO18005510/DI0OFF (0) 
11:18:10 08-May-2024EventStraddle K7SYSTEMO18005510/DI0ON (1) 
11:21:40 08-May-2024EventStraddle K8SYSTEMO18005510/DI0OFF (0) 
11:20:27 08-May-2024EventStraddle K8SYSTEMO18005510/DI0ON (1) 
11:20:26 08-May-2024EventStraddle K8SYSTEMO18005510/DI0OFF (0) 
11:20:25 08-May-2024EventStraddle K8SYSTEMO18005510/DI0ON (1) 
11:19:19 08-May-2024EventStraddle K8SYSTEMO18005510/DI0OFF (0) 
11:18:10 08-May-2024EventStraddle K8SYSTEMO18005510/DI0ON (1) 

 

Result

TypeOD CommentFN nameEntityOn TimeOff TimeUsername
EventStraddle K7SYSTEMO18005510/DI011:20:27 08-May-202411:21:40 08-May-2024 
EventStraddle K7SYSTEMO18005510/DI011:20:25 08-May-202411:20:26 08-May-2024 
EventStraddle K7SYSTEMO18005510/DI011:18:10 08-May-202411:19:19 08-May-2024 
EventStraddle K8SYSTEMO18005510/DI011:20:27 08-May-202411:21:40 08-May-2024 
EventStraddle K8SYSTEMO18005510/DI011:20:25 08-May-202411:20:26 08-May-2024 
EventStraddle K8SYSTEMO18005510/DI011:18:10 08-May-202411:19:19 08-May-2024 

 

 

Thanks for your help 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

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.

View solution in original post

3 REPLIES 3
Fthrs_Analytics
Frequent Visitor

You could use Text.End in Power Query to extract the last characters of the column to create an ON/OFF column

lbendlin
Super User
Super User

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. 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.