March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello,
How do I convert my table into a list based on selected values?
This is what I have
Identification Number | Category | All Other columns |
A-123 | Apple | |
A-123 | Mango | |
A-123 | Banana | |
B-456 | Pineapple | |
B-456 | Watermelon |
What I need
Identification Number | Category |
A-123 | Apple, Mango, Banana |
B-456 | Pineapple, Watermelon |
Solved! Go to Solution.
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.
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.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingHi, 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.
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.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI Reportingthank you so much!
Glad I could help @StoryofData
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingMarch 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
21 | |
16 | |
13 | |
12 | |
9 |
User | Count |
---|---|
34 | |
31 | |
20 | |
19 | |
17 |