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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
EaglesTony
Post Prodigy
Post Prodigy

I need a way to collapse a table onto itself

I have this table:

 

Item    Name

1         Orange

1         Apple

2         Apple

 

I need to collapse it onto itself, so it comes out

 

Item    Name

1         Orange, Apple

2         Apple

 

 

Thanks

 

1 ACCEPTED SOLUTION

@EaglesTony  You have to Group By Item column like below, then add a custom column using below expression.

 

JaiRathinavel_0-1732286677785.png

= Text.Combine(Table.Column([Custom], "Name"), ", ")

 

Did I answer your question? If yes, please mark my post as a solution. 

 

Thanks,

Jai




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

Proud to be a Super User!





View solution in original post

12 REPLIES 12
Anonymous
Not applicable

Hi,Jai-Rathinavel ,thanks for your concern about this issue.

Your answer is excellent!
And I would like to share some additional solutions below.

Hello,@EaglesTony . I am glad to help you.
Jai-Rathinavel is spot on with his suggestions, here is my test of what he suggests, hope it helps.

vjtianmsft_0-1732507822681.png
This is my test data:

vjtianmsft_1-1732507860507.png

You only need to add one step
Grouping by Item, where the logic is Text.Combine

 

 

 

=Table.Group(#"Changed Type", {"Item"}, {{"Count", each Text.Combine([Name],", ")}})

 

 

 

vjtianmsft_2-1732507929429.png

 this is my M code:

 

 

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\username\Desktop\test_11_25.xlsx"), null, true),
    TableTest_Sheet = Source{[Item="TableTest",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(TableTest_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Item", Int64.Type}, {"Name", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Item"}, {{"Count", each Text.Combine([Name],", ")}})
    
in
    #"Grouped Rows"

 

 

 

Item

Name

1

Orange

1

Apple

2

Banana

3

Orange

3

Cherry

4

Banana

4

Mango

4

Apple

5

Mango

vjtianmsft_3-1732507987027.png


If you find my suggestion helpful, you can mark Jai-Rathinavel's suggestion as a solution, which will help more users.


I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian

 

EaglesTony
Post Prodigy
Post Prodigy

I cant due to firewall rules.

 

Basically, based off this, assume table name is (Fruit):

 

Item    Name

1         Orange

1         Apple

2         Apple

 

I need to collapse it onto itself, so it comes out

 

Item    Name

1         Orange, Apple

2         Apple

 

I need steps on what column to group by, etc ?

@EaglesTony  You have to Group By Item column like below, then add a custom column using below expression.

 

JaiRathinavel_0-1732286677785.png

= Text.Combine(Table.Column([Custom], "Name"), ", ")

 

Did I answer your question? If yes, please mark my post as a solution. 

 

Thanks,

Jai




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

Proud to be a Super User!





EaglesTony
Post Prodigy
Post Prodigy

I don't need the Source, as I have these in a table called IssueComponents.

 

Within this table do I need to group by 1 or more columns ?

@EaglesTony , Can you send me your power query table view so that I can answer precisely ? Thanks

 




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

Proud to be a Super User!





Jai-Rathinavel
Super User
Super User

@EaglesTony , I have achieved it using a calculated column and field parameter.

Please check the attached pbix file Download PBIX

Expand

JaiRathinavel_0-1732128129371.png

Collapse

JaiRathinavel_1-1732128168440.png

Did I answer your question? If yes, please mark my post as a solution.

 

Thanks,

Jai

 




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

Proud to be a Super User!





Can you post the logic here instead of the download ?

@EaglesTony here you go,

1. Create a calculated column using this dax

Collapse = 
CALCULATE(
    CONCATENATEX('Table','Table'[Name],", "),
                ALLEXCEPT('Table','Table'[Item])
    )

2. Create a calculated table as a field parameter using below dax

Switch = {
    ("Expand", NAMEOF('Table'[Name]), 0),
    ("Collapse", NAMEOF('Table'[Collapse]), 1)
}

2. Pull in the field parameter both in Slicer and the visual

3. Make the slicer to Single select

 

Did I answer your question? If yes, please mark my post as a solution.

 

Thanks,

Jai

 




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

Proud to be a Super User!





There would be no slicer, just the table where it has the 2 rows (1 with both Orange and Apple and the other with just Apple).

 

Also, any way to do this in a Power M Query, as I eventually have to merge this to another table as a seperate column ?

 

I just need this at the end:

 

Item    Name

1         Orange, Apple

2         Apple

@EaglesTony , Please copy paste the below m query 

let
    Source = Table.FromRows(
        {
            {1, "Orange"},
            {1, "Apple"},
            {2, "Apple"}
        },
        {"Item", "Name"}
    ),
    #"Grouped Rows" = Table.Group(Source, {"Item"}, {{"Custom", each _, type table [Item=nullable number, Name=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Name", each Text.Combine(Table.Column([Custom], "Name"), ", ")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Custom"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Item", type text}, {"Name", type text}})
in
    #"Changed Type"

 Input:

JaiRathinavel_0-1732130671353.png

Output:

JaiRathinavel_1-1732130701755.png

 

Did I answer your question? If yes, please mark my post as a solution.

 

Thanks,

Jai

 

 




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

Proud to be a Super User!





So it is using a Group by ?

@EaglesTony yes, the end result is what as expected !




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

Proud to be a Super User!





Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Kudoed Authors
Users online (1,965)