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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.