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
hiken
New Member

Merging dynamically each 2 columns Excel Power Query

Hello,
I've struggling for days with this and can't get it right, please assist.
I want to merge dynamically earch 2 columns in the table, the number of columns are changing and that's why

this is the column

hiken_1-1674580306166.png

and here is it after tranposing the table

hiken_2-1674580356023.png

and this is the expected output, each 2 columns merged with comma delimited

hiken_3-1674580402159.png

appreciate any help
Thanks.

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @hiken ,
I would do it like so:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lFyNAIRxiDCRClWJ1rJCSTqBBJ1Aok6QUSdQaLOIFFnkKgzUDQWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
    AddFieldValues = Table.AddColumn(#"Changed Type", "FieldValues", each Record.FieldValues(_)),
    AddPairs = Table.AddColumn(AddFieldValues, "Pairs", each {0..(List.Count([FieldValues])/2)-1}),
    AddCombinations = Table.AddColumn(AddPairs, "Combinations", each List.Transform([Pairs], (l)=> Text.Combine(List.Range([FieldValues],(l*2),2), ", "))),
    CreateNewTable = Table.FromRows( AddCombinations[Combinations] )
in
    CreateNewTable

Please also check the file enclosed.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

1 REPLY 1
ImkeF
Community Champion
Community Champion

Hi @hiken ,
I would do it like so:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lFyNAIRxiDCRClWJ1rJCSTqBBJ1Aok6QUSdQaLOIFFnkKgzUDQWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
    AddFieldValues = Table.AddColumn(#"Changed Type", "FieldValues", each Record.FieldValues(_)),
    AddPairs = Table.AddColumn(AddFieldValues, "Pairs", each {0..(List.Count([FieldValues])/2)-1}),
    AddCombinations = Table.AddColumn(AddPairs, "Combinations", each List.Transform([Pairs], (l)=> Text.Combine(List.Range([FieldValues],(l*2),2), ", "))),
    CreateNewTable = Table.FromRows( AddCombinations[Combinations] )
in
    CreateNewTable

Please also check the file enclosed.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

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.