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
Shan_Drex12
Helper I
Helper I

Matching Different Column Names in Power Query

Hi All,

 

I wanted to know if you can match or merge two tables inside of power query that has different names. For example, if I have this  template sheet below:

 

Brand_Name Common_NameConstituent _Element_UOM4
nullnull 
nullnull 
nullnull 
nullnull 
nullnull 

 

And the table is the Upload Sheet that I want to merge it with:

 

Brand NameCommon NameConstituent Element UOM 4
Lasso NavCatheter, Electrode Recording Or Probe, Electrode Recording2456
WEBSTER CSCatheter, Electrode Recording Or Probe, Electrode Recording1123
Reference Patch CARTO 3computer, diagnostic, programmable3245
ThermoCool SmartTouchCardiac Ablation Percutaneous Catheter5777
   

 

Some of the column names are not that similar some have just one name that are the same. 

 

Your help would be greatly apreciated! 🙂

 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Shan_Drex12 

 

if your column are not in the same order you can use a more advanced program to do that. Basically uses the column names as table and join them with a fuzzy join. Then using the table to make the renaming. Here the code

let
    TableA = 
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSgVEKSrE6VBaLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Brand_Name " = _t, Common_Name = _t, #"Constituent _Element_UOM4" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Brand_Name ", type text}, {"Common_Name", type text}, {"Constituent _Element_UOM4", type text}})
    in
        #"Changed Type",
    TableB = 
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pY8xD4JADIX/SnMzC6IyK2EzSoDEgTCUUoGEu5Jy+Pu9kLi5Ofd733ttGnPDdRW449tEJkM/smeNIJ+ZvErPUDKJ9pMb4KFQqHT88xrSh+PpbNqoMc/8WtV5CVn1tzOOD8nuLPnFyo4YCvQ0QnYp6wckASGxy7YX9BMOTlY/UQSLyqBoLXYzBygJ43ZPPbJayURmqCyqr2WjcZ8ZKpHg0s3oJ3FQsNLm0bFsK3yfCOApTVPTth8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Brand Name" = _t, #"Common Name" = _t, #"Constituent Element UOM 4" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Brand Name", type text}, {"Common Name", type text}, {"Constituent Element UOM 4", Int64.Type}})
    in
        #"Changed Type",
    GetTableFromColumnNamesA = Table.TransformColumnTypes
    (
        Table.FromList
        (
            Table.ColumnNames(TableA),
            Splitter.SplitByNothing(),
            {"A"}
        ),
        {{"A", type text}}
    ),
    GetTableFromColumnNamesB = Table.TransformColumnTypes
    (
        Table.FromList
        (
            Table.ColumnNames(TableB),
            Splitter.SplitByNothing(),
            {"B"}
        ),
        {{"B", type text}}
    ),
    GetRenamingTable = Table.FuzzyJoin
    (
        GetTableFromColumnNamesA,
        {"A"},
        GetTableFromColumnNamesB,
        {"B"},
        JoinKind.LeftOuter,
        [Threshold= 0.5, IgnoreCase=true]
    ),
    RenameAtoB = Table.RenameColumns
    (
        TableA,
        List.Zip({GetRenamingTable[A], GetRenamingTable[B]})
    ),
    CombineTables = Table.Combine
    (
        {
            RenameAtoB,
            TableB
        }
    )
in
    CombineTables

uses tableA

Jimmy801_0-1613819196467.png

 

and TableB

Jimmy801_1-1613819210512.png

 

to generate the renming table

Jimmy801_2-1613819229266.png

 and renames table a to get this final result

Jimmy801_3-1613819248825.png

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

4 REPLIES 4
Jimmy801
Community Champion
Community Champion

Hello @Shan_Drex12 

 

if your column are not in the same order you can use a more advanced program to do that. Basically uses the column names as table and join them with a fuzzy join. Then using the table to make the renaming. Here the code

let
    TableA = 
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSgVEKSrE6VBaLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Brand_Name " = _t, Common_Name = _t, #"Constituent _Element_UOM4" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Brand_Name ", type text}, {"Common_Name", type text}, {"Constituent _Element_UOM4", type text}})
    in
        #"Changed Type",
    TableB = 
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pY8xD4JADIX/SnMzC6IyK2EzSoDEgTCUUoGEu5Jy+Pu9kLi5Ofd733ttGnPDdRW449tEJkM/smeNIJ+ZvErPUDKJ9pMb4KFQqHT88xrSh+PpbNqoMc/8WtV5CVn1tzOOD8nuLPnFyo4YCvQ0QnYp6wckASGxy7YX9BMOTlY/UQSLyqBoLXYzBygJ43ZPPbJayURmqCyqr2WjcZ8ZKpHg0s3oJ3FQsNLm0bFsK3yfCOApTVPTth8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Brand Name" = _t, #"Common Name" = _t, #"Constituent Element UOM 4" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Brand Name", type text}, {"Common Name", type text}, {"Constituent Element UOM 4", Int64.Type}})
    in
        #"Changed Type",
    GetTableFromColumnNamesA = Table.TransformColumnTypes
    (
        Table.FromList
        (
            Table.ColumnNames(TableA),
            Splitter.SplitByNothing(),
            {"A"}
        ),
        {{"A", type text}}
    ),
    GetTableFromColumnNamesB = Table.TransformColumnTypes
    (
        Table.FromList
        (
            Table.ColumnNames(TableB),
            Splitter.SplitByNothing(),
            {"B"}
        ),
        {{"B", type text}}
    ),
    GetRenamingTable = Table.FuzzyJoin
    (
        GetTableFromColumnNamesA,
        {"A"},
        GetTableFromColumnNamesB,
        {"B"},
        JoinKind.LeftOuter,
        [Threshold= 0.5, IgnoreCase=true]
    ),
    RenameAtoB = Table.RenameColumns
    (
        TableA,
        List.Zip({GetRenamingTable[A], GetRenamingTable[B]})
    ),
    CombineTables = Table.Combine
    (
        {
            RenameAtoB,
            TableB
        }
    )
in
    CombineTables

uses tableA

Jimmy801_0-1613819196467.png

 

and TableB

Jimmy801_1-1613819210512.png

 

to generate the renming table

Jimmy801_2-1613819229266.png

 and renames table a to get this final result

Jimmy801_3-1613819248825.png

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Shan_Drex12
Helper I
Helper I

Thanks @MattAllington 

 

Is there a way to automatically switch around the columns that match the other table template? Or is there a way to match the data based on linking particular data columns?

If the column count is the same and in the same order, it is fairly simple with this pattern @Shan_Drex12 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pY8xD4JADIX/SnMzC6IyK2EzSoDEgTCUUoGEu5Jy+Pu9kLi5Ofd733ttGnPDdRW449tEJkM/smeNIJ+ZvErPUDKJ9pMb4KFQqHT88xrSh+PpbNqoMc/8WtV5CVn1tzOOD8nuLPnFyo4YCvQ0QnYp6wckASGxy7YX9BMOTlY/UQSLyqBoLXYzBygJ43ZPPbJayURmqCyqr2WjcZ8ZKpHg0s3oJ3FQsNLm0bFsK3yfCOApTVPTth8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Brand Name" = _t, #"Common Name" = _t, #"Constituent Element UOM 4" = _t]),
    #"Appended Query" = 
        Table.Combine(
            {
                Source,
                Table.RenameColumns(
                    Table1,
                        {
                            {Table.ColumnNames(Table1){0}, Table.ColumnNames(Source){0}},
                            {Table.ColumnNames(Table1){1}, Table.ColumnNames(Source){1}},
                            {Table.ColumnNames(Table1){2}, Table.ColumnNames(Source){2}}
                        }
                )
            }
        )
in
    #"Appended Query"

 

 This is in Table2 - your second table.

It appends Table1, but instead of just getting table1, it renames the columns the same as table2, assuming they are in the same order.

 

Here is my PBIX file if you want to look at it work.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
MattAllington
Community Champion
Community Champion

The column names have to be the same to append tables. Of course, you can change the column names in one table to match another - that will work for a small number of tables. Another approach is to demote the headers so all the columns are Col1, Col2, Col3, etc and you can remove the top row. If you do this, the column names will be appended based on position (technically it is still the name).  Of course, you need to make sure the data in the columns is the same type, even if you do change column names. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

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.