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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Grouping data

I am monitoring a real-world event and analysing the data in powerBI. 

Every time this real-world event occurs, exactly 4 events, of types 1,2,3, and 4 are logged to the system. 

 

Event id 1 will always be first, but the order of the remainin 3 may vary: 

 

time, event_id, event_data
09:00, 1, xxxxx
09:01, 2, xxxxx
09:02, 3, xxxxx
09:03, 4, xxxxx
09:04, 1, xxxxx
09:05, 4, xxxxx
09:06, 2, xxxxx
09:07, 3, xxxxx

 

I am looking for a way to group these 4 events each time they occur - probably into a single row - such that I can perform further analysis on them. I suspect I can use event_id 1 as my delimiter, since I know it will always come first.....


event_count, time_1, event_1_data, time_2, event_2_data, time_3, event_3_data, time_4, event_4_data
1, 09:00, xxxx, 09:01, xxxxxx, 09:02, xxxxx, 09:03, xxxx
2, 09:04, xxxx, 09:06, xxxxxx, 09:07, xxxxx, 09:05, xxxx

 

but am struggling to implement this within powerBI

Any pointers would be very welcome!

 

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

You can achieve your requirement in PowerQuery.

This M code works:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrC0MjBQ0lEyBOIKEFCK1YGIgkSMMERBIsYYoiAREwxRE6zmmmJVa4bVNnNU22IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [time = _t, event_id = _t, event_data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"time", type time}, {"event_id", Int64.Type}, {"event_data", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", "event_id", {{"Data", each Table.AddColumn( Table.Sort(_,"event_id"),"Temp",(x)=>Text.From( x[time])&","&x[event_data])[Temp]   }},0,(x,y)=>Number.From(y=1)),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "ID", 1, 1, Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Added Index",{"event_id"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ID", "Data"}),
    Custom1 = Table.TransformColumns(#"Reordered Columns",{"Data",each Text.Combine(_,",")}),
    #"Split Column by Delimiter" = Table.SplitColumn(Custom1, "Data", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Data.1", "Data.2", "Data.3", "Data.4", "Data.5", "Data.6", "Data.7", "Data.8"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Data.1", type time}, {"Data.2", type text}, {"Data.3", type time}, {"Data.4", type text}, {"Data.5", type time}, {"Data.6", type text}, {"Data.7", type time}, {"Data.8", type text}})
in
    #"Changed Type1"

 

 

1.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

You can achieve your requirement in PowerQuery.

This M code works:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrC0MjBQ0lEyBOIKEFCK1YGIgkSMMERBIsYYoiAREwxRE6zmmmJVa4bVNnNU22IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [time = _t, event_id = _t, event_data = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"time", type time}, {"event_id", Int64.Type}, {"event_data", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", "event_id", {{"Data", each Table.AddColumn( Table.Sort(_,"event_id"),"Temp",(x)=>Text.From( x[time])&","&x[event_data])[Temp]   }},0,(x,y)=>Number.From(y=1)),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "ID", 1, 1, Int64.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Added Index",{"event_id"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"ID", "Data"}),
    Custom1 = Table.TransformColumns(#"Reordered Columns",{"Data",each Text.Combine(_,",")}),
    #"Split Column by Delimiter" = Table.SplitColumn(Custom1, "Data", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Data.1", "Data.2", "Data.3", "Data.4", "Data.5", "Data.6", "Data.7", "Data.8"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Data.1", type time}, {"Data.2", type text}, {"Data.3", type time}, {"Data.4", type text}, {"Data.5", type time}, {"Data.6", type text}, {"Data.7", type time}, {"Data.8", type text}})
in
    #"Changed Type1"

 

 

1.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

selimovd
Super User
Super User

Hey @Anonymous ,

 

is there a reason to group the data?

You can analyze better when you let them in the original format.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
Anonymous
Not applicable

my reason for wanting to group the data is that currently each real-world event generates logged events 1,2,3, and 4 - so 4 rows in my table - but there is nothing to easily flag them as relating to the same real-world event. 

 

To analyse each real-world event I need some way of logically flagging these 4 events as being related - whether that is by merging them into a single row, or by allocating a unique "real world ID" to each of the 4 rows that I can use as a flag to differentiate them - or perhaps some other method I have yet to come up with

Anonymous
Not applicable

I'm wondering if powerBI is the right tool for this....it seems to sit in an odd niche between the data source itself and the presentation to the user....

 

Conceptually I can see I could loop through the data, taking event 1 as my "real-world-event delimiter" and flagging each of the subsequent events as part of that original event. But I'm not sure this is something I can do in powerBI, as opposed to at the data source itself....

Anonymous
Not applicable

Any ideas on this...? 

I could try to pre-process the data outside of powerBI, but it would be nice not to hjave to if possible. 

 

I looked at using pythoin integration, but I think that then I can not publish to the web...? 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.