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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
cher90
Helper II
Helper II

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
v-stephen-msft
Community Support
Community Support

Hi @cher90 ,

 

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
v-stephen-msft
Community Support
Community Support

Hi @cher90 ,

 

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.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors