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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Goodkat
Helper II
Helper II

Congruent Header Rename based on List

Dear Power Query enthusiasts,

 

Today I worked on the topic of automated header renaming in power query. And now I am struggling with the last step. I have a query on which the header names are incorrect. At the same time I have a list were I know the headers are correct. Both are congruent, i.e. Header for column 1 sits in [mdHeader]row 1, column 2 = row 2 and so forth.

Which command I would need to implement into the Table.RenameColumns command to achieve this? I searched the internet intensively and watched numerous videos over the past hours, but none could give me a clue how to perform this 'transposed copy rename' operation in one commandline in [Header] query.

 

Any idea from the community will be greatly appreciated!

 

https://c.gmx.net/@324888734501700174/6aAbqAZdQkKdWVkovk3c-w

 

Best regards, Andreas

1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Hello!  Here is how you can accomplish this.

If you have a table of data:

jennratten_4-1702909433105.png

And a table of column headers:

jennratten_1-1702909025612.png

You can rename them like so (for ease of understanding I have broken the actions into separate steps, but these can be combined into one step if preferred).  I have included two options - one for getting the old names from the source data and the other for getting the old names from the table which also contains the new names.

jennratten_2-1702909258273.png

After the renaming is applied:

jennratten_3-1702909404174.png

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WctRTcEksKc1VcM4vKsgvSizJzM9TUNAI1QvW01TSUfJzVorViVbyBcoU6Si4FyVmJOYqJOalKLhkJmen5hUDlfi6KMXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Account Name" = _t, #"State or Province" = _t]),
    FieldNames = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckxOzi/NK1HwS8xNVdKBcZVidaKVgksSS1IV8osUAoryyzLzkkHyYDGl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [old = _t, new = _t]),

    // list of old names if they are coming from the source data.
    varOldNames = Table.ColumnNames ( Source ),

    // list of old names if they are in a table with the new names, aka a data map.
    // varOldNames = Table.Column ( FieldNames, "old" ),

    // list of new names
    varNewNames = Table.Column ( FieldNames, "new" ),

    // zip the old names and new names together into a list.
    OldNewList = List.Zip ( 
        {
            varOldNames, varNewNames
        }
    ),

    // rename the columns in the table using the zipped list.
    RenameColumns = Table.RenameColumns ( Source, OldNewList )
in
    RenameColumns

 

 

View solution in original post

2 REPLIES 2
jennratten
Super User
Super User

Hello!  Here is how you can accomplish this.

If you have a table of data:

jennratten_4-1702909433105.png

And a table of column headers:

jennratten_1-1702909025612.png

You can rename them like so (for ease of understanding I have broken the actions into separate steps, but these can be combined into one step if preferred).  I have included two options - one for getting the old names from the source data and the other for getting the old names from the table which also contains the new names.

jennratten_2-1702909258273.png

After the renaming is applied:

jennratten_3-1702909404174.png

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WctRTcEksKc1VcM4vKsgvSizJzM9TUNAI1QvW01TSUfJzVorViVbyBcoU6Si4FyVmJOYqJOalKLhkJmen5hUDlfi6KMXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Account Name" = _t, #"State or Province" = _t]),
    FieldNames = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckxOzi/NK1HwS8xNVdKBcZVidaKVgksSS1IV8osUAoryyzLzkkHyYDGl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [old = _t, new = _t]),

    // list of old names if they are coming from the source data.
    varOldNames = Table.ColumnNames ( Source ),

    // list of old names if they are in a table with the new names, aka a data map.
    // varOldNames = Table.Column ( FieldNames, "old" ),

    // list of new names
    varNewNames = Table.Column ( FieldNames, "new" ),

    // zip the old names and new names together into a list.
    OldNewList = List.Zip ( 
        {
            varOldNames, varNewNames
        }
    ),

    // rename the columns in the table using the zipped list.
    RenameColumns = Table.RenameColumns ( Source, OldNewList )
in
    RenameColumns

 

 

Dear Jenn,

Thank you so much! How cool! It works! And so crisp & clear! I just ran a test in my original data with all of the commands merged into one line as you suggested. And it does the trick! I will put this solution into my little Power Query learning compilation.

Have a good day, or rest of the day, and a joyful upcoming holiday season!

 

Many greetings, Andreas

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.