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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
kladkent
Regular Visitor

Custom Column in Power query, Returns column values from different rows with same column ID

power bi inquiry.png

 Hello Guys!

 

I need to create a custom column that combines all the "ITEM" with the same "ID".

 

Thanks,

 

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @kladkent ,

 

Try this example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJydFeK1YGwfRwDQvwDwFwjINfVMSjAw9/PFS4Q4Orn7OmD4MIljYE8b9dIJ3/HIBe4gLOHo2eQUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, ITEM = _t]),

    groupRows = Table.Group(Source, {"ID"}, {{"data", each _, type table [ID=nullable text, ITEM=nullable text]}, {"CUSTOM COLUMN", each Text.Combine([ITEM], ", "), type nullable text}}),
    expandDataCol = Table.ExpandTableColumn(groupRows, "data", {"ITEM"}, {"ITEM"})
    
in
    expandDataCol

 

You basically group your table on [ID] and add an 'All Rows' aggregated column and a 'SUM' column on [ITEM].

This obviously gives an error, so you adjust your Group By code to change List.Sum([ITEM]) to Text.Combine([ITEM], ", ").

You then expand the [ITEM] column back out from the nested All Rows column.

 

Example output:

BA_Pete_0-1690529176836.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @kladkent ,

 

Try this example query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJydFeK1YGwfRwDQvwDwFwjINfVMSjAw9/PFS4Q4Orn7OmD4MIljYE8b9dIJ3/HIBe4gLOHo2eQUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, ITEM = _t]),

    groupRows = Table.Group(Source, {"ID"}, {{"data", each _, type table [ID=nullable text, ITEM=nullable text]}, {"CUSTOM COLUMN", each Text.Combine([ITEM], ", "), type nullable text}}),
    expandDataCol = Table.ExpandTableColumn(groupRows, "data", {"ITEM"}, {"ITEM"})
    
in
    expandDataCol

 

You basically group your table on [ID] and add an 'All Rows' aggregated column and a 'SUM' column on [ITEM].

This obviously gives an error, so you adjust your Group By code to change List.Sum([ITEM]) to Text.Combine([ITEM], ", ").

You then expand the [ITEM] column back out from the nested All Rows column.

 

Example output:

BA_Pete_0-1690529176836.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




 

You're welcome.

Don't forget to give a thumbs-up on any posts that have helped you 👍

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.