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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
dpeper6
Helper I
Helper I

How to merge several columns named like XXX_1 XXX_2.... into only one, adding rows for each column

Hey Guys!


I need some help as I have been trying to do this by 3 days with no luck 😞

 

After some combining, cleaning and transformig I have table with the data I need for do the report but, power query named the columns of the same name (after a transponse transformation) with _ like: EBITDA (the original) and then EBITDA_1, EBITDA_2 to... EBITDA_3000 I would want to merge all this columns into the first one... any thoughts? 

 

dpeper6_0-1664718609335.png

 

For some clarification until the transponse the table is something like that:

dpeper6_0-1664719015542.png

 

 

Thanks in advance :)!

1 ACCEPTED SOLUTION

Hi @dpeper6 

 

Yes. And you may need to modify the M code in Advanced Editor manually. Here is an example. 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY/BCoMwDIZfRXpWaZOm6lG3HXrZYewmHtzUURgTtr0/a1XECmuhJLRfPvLXNSPOIQdgMTuY4d1GXR+d+8d4N+PHvolMSom56+yxBQRr4u3UqdLXYzn9IHHlGppJy+zYS//6tjfzNF3bResgXy4i7vgqLVOdOhdXOLsFoS0UNFel3mphYUUhiz8xF1Shj64rJshBiWzqQE60B4aDkVQ+vubaehU5MQBgwO1HS4g1zQ8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"CB AGRUPADO" = _t, Concepto = _t, #"PPTO INICIAL" = _t, UPA = _t, XXXX = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CB AGRUPADO", Int64.Type}, {"Concepto", type text}, {"PPTO INICIAL", Int64.Type}, {"UPA", Int64.Type}, {"XXXX", Int64.Type}}),
    
    // Select first three columns and pivot 
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"CB AGRUPADO", "Concepto", "PPTO INICIAL"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Other Columns", List.Distinct(#"Removed Other Columns"[Concepto]), "Concepto", "PPTO INICIAL"),
    
    // Select first two columns and the 4th column, then pivot
    #"Removed Other Columns 2" = Table.SelectColumns(#"Changed Type",{"CB AGRUPADO", "Concepto", "UPA"}),
    #"Pivoted Column 2" = Table.Pivot(#"Removed Other Columns 2", List.Distinct(#"Removed Other Columns 2"[Concepto]), "Concepto", "UPA"),
    
    // Select first two columns and the 5th column, then pivot
    #"Removed Other Columns 3" = Table.SelectColumns(#"Changed Type",{"CB AGRUPADO", "Concepto", "XXXX"}),
    #"Pivoted Column 3" = Table.Pivot(#"Removed Other Columns 3", List.Distinct(#"Removed Other Columns 3"[Concepto]), "Concepto", "XXXX"),
    
    // Append above three tables
    #"Append all tables" = Table.Combine({#"Pivoted Column", #"Pivoted Column 2", #"Pivoted Column 3"})
in
    #"Append all tables"

 

vjingzhang_0-1664937724373.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

8 REPLIES 8
v-jingzhang
Community Support
Community Support

Hi @dpeper6 

 

What is your expected result like? Do you want something like below?

vjingzhang_0-1664873282810.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

but I will need to this for all the columns? I need the one that have de primary key (CB Agrupado) in all of them....

Hi @dpeper6 

 

Yes. And you may need to modify the M code in Advanced Editor manually. Here is an example. 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY/BCoMwDIZfRXpWaZOm6lG3HXrZYewmHtzUURgTtr0/a1XECmuhJLRfPvLXNSPOIQdgMTuY4d1GXR+d+8d4N+PHvolMSom56+yxBQRr4u3UqdLXYzn9IHHlGppJy+zYS//6tjfzNF3bResgXy4i7vgqLVOdOhdXOLsFoS0UNFel3mphYUUhiz8xF1Shj64rJshBiWzqQE60B4aDkVQ+vubaehU5MQBgwO1HS4g1zQ8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"CB AGRUPADO" = _t, Concepto = _t, #"PPTO INICIAL" = _t, UPA = _t, XXXX = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CB AGRUPADO", Int64.Type}, {"Concepto", type text}, {"PPTO INICIAL", Int64.Type}, {"UPA", Int64.Type}, {"XXXX", Int64.Type}}),
    
    // Select first three columns and pivot 
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"CB AGRUPADO", "Concepto", "PPTO INICIAL"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Other Columns", List.Distinct(#"Removed Other Columns"[Concepto]), "Concepto", "PPTO INICIAL"),
    
    // Select first two columns and the 4th column, then pivot
    #"Removed Other Columns 2" = Table.SelectColumns(#"Changed Type",{"CB AGRUPADO", "Concepto", "UPA"}),
    #"Pivoted Column 2" = Table.Pivot(#"Removed Other Columns 2", List.Distinct(#"Removed Other Columns 2"[Concepto]), "Concepto", "UPA"),
    
    // Select first two columns and the 5th column, then pivot
    #"Removed Other Columns 3" = Table.SelectColumns(#"Changed Type",{"CB AGRUPADO", "Concepto", "XXXX"}),
    #"Pivoted Column 3" = Table.Pivot(#"Removed Other Columns 3", List.Distinct(#"Removed Other Columns 3"[Concepto]), "Concepto", "XXXX"),
    
    // Append above three tables
    #"Append all tables" = Table.Combine({#"Pivoted Column", #"Pivoted Column 2", #"Pivoted Column 3"})
in
    #"Append all tables"

 

vjingzhang_0-1664937724373.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

This worked well :)!! thx!!

Yep! That's exactly what I need :)!

Greg_Deckler
Super User
Super User

@dpeper6 Select all of the columns you want to merge while holding down the Ctrl key. Click on the Transform tab in the ribbon and then Merge Columns (in the Text Column area of the ribbon)



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

If I do so... it will merge the content in a single column and each of the columns must add a new line, for clarification I have added the table without transponse, thanks! 🙂

@dpeper6 I missed the added rows. OK, don't merge but select your columns and unpivot?



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.