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
Anonymous
Not applicable

Dynamic - Grouping by a Measure column - combining the text values

I have a table "School" :

School
ClassNamesCounts
c1XXX1
c1YYY2
c2ZZZ3
c2AAA4
c3AAA2
c3BBB3
c4BBB2
c5CCC0
c5CCC1
c5DDD2
c6FFF1


I have created a 'Total Counts' groupby 'Names' column & created Rank based on 'Total count' Measure.

NamesTotal countsRank
AAA61
BBB52
ZZZ33
DDD24
YYY24
CCC15
FFF15
XXX15


I wanted to create a 'new column' called 'Updated Names' which concatenate the value as shown in the below table based on 'Total Counts' column (Dynamically Grouping by a Measure column - combining the values)

Expected output 
Updated NamesTotal countsRank
AAA61
BBB52
ZZZ33
DDD,YYY24
CCC,FFF,XXX15
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

11.png

When you complete this step, write the following statement in the advanced editor, then sort in descending order and add an index column. The index column is your Rank column.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XctLCsAgDEXRvWTsoH7auVFcg4k46v730AeKgU4uj0MyBr2eHPXeUU/TbRARNCwImKqKRoOcM5oWxAPBgJntJR3YFzdmKQW9/uANaq328mC21tbF/AA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Class = _t, Names = _t, Counts = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Class", type text}, {"Names", type text}, {"Counts", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Names"}, {{"Total counts", each List.Sum([Counts]), type nullable number}}),
    #"Combined Values"= Table.Group(#"Grouped Rows" , {"Total counts"}, {{"Combine Values", each Text.Combine([Names], ","), type text}}),
    #"Sorted Rows" = Table.Sort(#"Combined Values",{{"Total counts", Order.Descending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
    #"Renamed Columns" = Table.RenameColumns(#"Added Index",{{"Index", "Rank"}})
in
    #"Renamed Columns"

12.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

 

11.png

When you complete this step, write the following statement in the advanced editor, then sort in descending order and add an index column. The index column is your Rank column.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XctLCsAgDEXRvWTsoH7auVFcg4k46v730AeKgU4uj0MyBr2eHPXeUU/TbRARNCwImKqKRoOcM5oWxAPBgJntJR3YFzdmKQW9/uANaq328mC21tbF/AA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Class = _t, Names = _t, Counts = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Class", type text}, {"Names", type text}, {"Counts", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Names"}, {{"Total counts", each List.Sum([Counts]), type nullable number}}),
    #"Combined Values"= Table.Group(#"Grouped Rows" , {"Total counts"}, {{"Combine Values", each Text.Combine([Names], ","), type text}}),
    #"Sorted Rows" = Table.Sort(#"Combined Values",{{"Total counts", Order.Descending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
    #"Renamed Columns" = Table.RenameColumns(#"Added Index",{{"Index", "Rank"}})
in
    #"Renamed Columns"

12.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@Anonymous Well, maybe a measure like:

Measure = 
  VAR __Rank = [Rank]
  VAR __Table =
    ADDCOLUMNS(
      SUMMARIZE('Table',[Names],"Counts",SUM('Table'[Counts])),
      "Rank",[Rank]
    )
RETURN
  CONCATENATEX(FILTER(__Table,[Rank]=__Rank),[Names],",")

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.