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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Ray_Brosius
Helper III
Helper III

Grouping in Power Query

I have a simple two column table

invoice and Product

 

there are mutliple products per invoice so there is a record per invocie and product combination

 

I want to end up with one record per invoice and a column that has the products in a csv string.

 

how do I do this?

 

InvoiceProduct
1a
1b
1c

 

End u pwith

 

Inovice

InvoiceProduct
1a,b,c
1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

Consider the table...

jgeddes_0-1694116158945.png

You can get the result...

jgeddes_1-1694116183575.png

With the code...

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpUitWBsJLgrGQwywguawQXMwayUpRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Invoice = _t, Product = _t]),
#"Grouped Rows" = Table.Group(Source, {"Invoice"}, {{"Product", each _, type table [Invoice=nullable text, Product=nullable text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Product], "Product")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Removed Columns" = Table.RemoveColumns(#"Extracted Values",{"Product"})
in
#"Removed Columns"




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

1 REPLY 1
jgeddes
Super User
Super User

Consider the table...

jgeddes_0-1694116158945.png

You can get the result...

jgeddes_1-1694116183575.png

With the code...

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpUitWBsJLgrGQwywguawQXMwayUpRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Invoice = _t, Product = _t]),
#"Grouped Rows" = Table.Group(Source, {"Invoice"}, {{"Product", each _, type table [Invoice=nullable text, Product=nullable text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Product], "Product")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Removed Columns" = Table.RemoveColumns(#"Extracted Values",{"Product"})
in
#"Removed Columns"




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

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.