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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

How to merge cell contents from one row into another cell/row ?

Hello, 

 

How to merge cell contents from one row/cell into another cell/row if they have the same ID

 

I have a table like this:

 

cher90_2-1666537669346.png

 

I am looking to merge the contents of "Data 6" line 7 into "Data 6" line 6 if in "ID" there is the same value. And then duplicate in the other cell.

 

the expected output:

 

cher90_3-1666537679981.png

 

I then intend to delete the duplicates to keep only one line.

 

Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

The whole M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZAxDoQgEEWvMplaEh3FPYSFByAUCnTbrQ23358xJARD5UuGvOa/Aud4UnhgGUXMNJraBb5veM7vQTjYlX4XYUEHYD84lptmVnzuJLCgE2hivmlmxRf4tj8TWFAI4WUhxqiFRalGtvK1+xGWcs4asEozKv7pBlZKKbH3fw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Data 1" = _t, #"Data 2" = _t, #"Data 3" = _t, #"Data 5" = _t, #"Data 6" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Data 1", type date}, {"Data 2", type date}, {"Data 3", type text}, {"Data 5", type text}, {"Data 6", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Tables", each _, type table [ID=nullable number, Data 1=nullable date, Data 2=nullable date, Data 3=nullable text, Data 5=nullable text, Data 6=nullable text]}, {"Combination", each Text.Combine([Data 6], "; "), type nullable text}}),
    #"Expanded Tables" = Table.ExpandTableColumn(#"Grouped Rows", "Tables", {"Data 1", "Data 2", "Data 3", "Data 5"}, {"Data 1", "Data 2", "Data 3", "Data 5"})
in
    #"Expanded Tables"

Steps:

1.Select ID column and then group by.

vstephenmsft_0-1666595291344.png

vstephenmsft_1-1666595371431.png

vstephenmsft_3-1666595514473.png

 

2.Edit the M code, we replace "List.Sum([Data 6])" with "each Text.Combine([Data 6], " "),"

13.png14.png

 

3.Expand the tables.

vstephenmsft_4-1666595724815.png

vstephenmsft_5-1666595731858.png

 

 

 

Reference: Power Query - Combine rows into a single cell - Excel Off The Grid

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

 

The whole M code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZAxDoQgEEWvMplaEh3FPYSFByAUCnTbrQ23358xJARD5UuGvOa/Aud4UnhgGUXMNJraBb5veM7vQTjYlX4XYUEHYD84lptmVnzuJLCgE2hivmlmxRf4tj8TWFAI4WUhxqiFRalGtvK1+xGWcs4asEozKv7pBlZKKbH3fw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Data 1" = _t, #"Data 2" = _t, #"Data 3" = _t, #"Data 5" = _t, #"Data 6" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Data 1", type date}, {"Data 2", type date}, {"Data 3", type text}, {"Data 5", type text}, {"Data 6", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Tables", each _, type table [ID=nullable number, Data 1=nullable date, Data 2=nullable date, Data 3=nullable text, Data 5=nullable text, Data 6=nullable text]}, {"Combination", each Text.Combine([Data 6], "; "), type nullable text}}),
    #"Expanded Tables" = Table.ExpandTableColumn(#"Grouped Rows", "Tables", {"Data 1", "Data 2", "Data 3", "Data 5"}, {"Data 1", "Data 2", "Data 3", "Data 5"})
in
    #"Expanded Tables"

Steps:

1.Select ID column and then group by.

vstephenmsft_0-1666595291344.png

vstephenmsft_1-1666595371431.png

vstephenmsft_3-1666595514473.png

 

2.Edit the M code, we replace "List.Sum([Data 6])" with "each Text.Combine([Data 6], " "),"

13.png14.png

 

3.Expand the tables.

vstephenmsft_4-1666595724815.png

vstephenmsft_5-1666595731858.png

 

 

 

Reference: Power Query - Combine rows into a single cell - Excel Off The Grid

 

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.

Anonymous
Not applicable

Thank you it works very well!

wdx223_Daniel
Super User
Super User

NewStep=Table.Combine(Table.Group(PreviousStepName,"ID",{"n",each Table.ReplaceValue(_,(x)=>Text.Combine([Data 6],","),"",(x,y,z)=>y,{"Data 6"})})[n])

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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