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
StoryofData
Helper III
Helper III

Rows to List

Hello, 

 

How do I convert my table into a list based on selected values?

 

This is what I have 

Identification NumberCategoryAll Other columns
A-123Apple 
A-123Mango 
A-123Banana 
B-456Pineapple 
B-456Watermelon 

 

What I need

Identification NumberCategory
A-123Apple, Mango, Banana
B-456Pineapple, Watermelon
1 ACCEPTED SOLUTION
edhans
Super User
Super User

Hi, you want to use the Table.Group feature, but you'll use a custom aggregation. I created it using a COUNT aggregation, then replaced it with Text.Combine. The _ represents the table (first one has 3 rows, 2nd one has 2 rows). The [Category] turns it to a list for the category field, and Text.Combine operates on that. 

edhans_0-1690404223084.png

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WctQ1NDJW0lFyLCjISQXSSrE6CEHfxLz0fHRBp8Q8IISJOumamJoBOQGZeamJyGbAJMITS1KLclNz8vPAMrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Identification Number" = _t, Category = _t, #"All Other columns" = _t]),
    #"Grouped Rows" = 
        Table.Group(
            Source, 
            {"Identification Number"}, 
            {
                {"List", each Text.Combine(_[Category], ", "), type text}
            }
        )
in
    #"Grouped Rows"

 

 How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

3 REPLIES 3
edhans
Super User
Super User

Hi, you want to use the Table.Group feature, but you'll use a custom aggregation. I created it using a COUNT aggregation, then replaced it with Text.Combine. The _ represents the table (first one has 3 rows, 2nd one has 2 rows). The [Category] turns it to a list for the category field, and Text.Combine operates on that. 

edhans_0-1690404223084.png

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WctQ1NDJW0lFyLCjISQXSSrE6CEHfxLz0fHRBp8Q8IISJOumamJoBOQGZeamJyGbAJMITS1KLclNz8vPAMrEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Identification Number" = _t, Category = _t, #"All Other columns" = _t]),
    #"Grouped Rows" = 
        Table.Group(
            Source, 
            {"Identification Number"}, 
            {
                {"List", each Text.Combine(_[Category], ", "), type text}
            }
        )
in
    #"Grouped Rows"

 

 How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

thank you so much!

Glad I could help @StoryofData 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.

Top Kudoed Authors