Get our FREE VBA eBook of the 30 most useful Excel VBA macros.

Automate Excel so that you can save time and stop doing the jobs a trained monkey could do.

Claim your free eBook

Power Query: Rename columns in nested tables from list (without errors)

Power Query - Rename Columns - without errors

Power Query is a nightmare when we want to combine data with different column names, and even worse when those columns are not in the same order. Can we even combine that data? You bet we can! We’re looking at that today; using Power Query to rename columns in nested tables based on a list, without creating errors.

In previous posts, I’ve used the code-stealing method, but not today; we will write the M code ourselves 😲. Don’t worry; it will all work out OK.

Download the example file: Click the link below to download the example file used for this post:

Watch the video

Watch the video on YouTube


In the example file, there are two queries: ExampleWorkbook and FindReplace.


In the ExcelWorkbook query, we connected to an Excel workbook with 3 worksheets (Sheet1, Sheet2, and Sheet3).

Worksheet Connected

Those worksheets have different column names and are in different orders.

  • Sheet1 – Column names: Item, Region, Value
  • Sheet2 – Column names: Product, Region, Value
  • Sheet3 – Column names: Item, Value, Division

Sheet column names are highlighted in the screenshots below.

Sheet views - different column names

If the columns were in the same order, we could combine them using the default Column1, Column2, and Column3 names. Then we would just rename the columns afterward.

But our columns are not in the same order; therefore, this won’t work. So, we need to pull some Power Query magic to achieve this.


The FindReplace query contains a table detailing the column names we wish to rename. We will use this later in the post.

Find Replace Table


OK, now let’s tackle this problem.

Promote Headers

Because the example data is an Excel Worksheet, the headers are been promoted automatically. The headers are currently Column1, Column2, and Column3.

To promote the headers of a nested table, click on the fx icon in the formula bar and end the following formula:

= Table.TransformColumns(Source, {{"Data", each Table.PromoteHeaders(_), type table}})

Let’s break this down a little bit:

  • Table.TransformColumns: The function for performing transformations on columns
  • Source: Name of the Table to perform the transformation on (i.e., the previous step)
  • “Data”: The column to perform the transformation on
  • each Table.PromoteHeaders(_): The transformation to perform. The keyword each and the underscore ( _ ) are used because we have a nested Table.
  • type table: The output of the transformation is a table data type.

Now, each of our Tables looks like this (headers promoted, but still different).

Sheet views after promote headers

Rename columns

OK, so now we can rename the column. Click the fx icon; in the formula bar, add the following function:

= Table.TransformColumns(Custom1, {{"Data", each Table.RenameColumns(_,{{"Product","Item"}}), type table}})

Let’s break this down also:

  • Table.TransformColumns: The function for performing transformations on columns
  • Custom1: Name of the Table to perform the transformation on (i.e., the previous step)
  • “Data”: The column to perform the transformation on
  • each Table.RenameColumns(_: The transformation to perform. The keyword each and the underscore ( _ ) are used because we have a nested Table.
  • {{“Product”,”Item”}}: The rename we wish to perform (e.g., rename Product to Item)
  • type table: The output of the transformation is a table data type.

Now look at the Preview Window in Power Query. Two of the Tables show errors.

Error after first rename

This occurs because only one table has a column called Product. The other tables do not have a Product column, so it creates an error.

Error message after rename

Let’s turn to the magic MissingField.Ignore argument. This is an optional argument of the Table.RenameColumns function. You’ll only really know it’s there if you look in the Power Query documentation, or write M code formulas yourself.

Change the transformation as follows:

= Table.TransformColumns(Custom1, {{"Data", each Table.RenameColumns(_,{{"Product","Item"}}, MissingField.Ignore), type table}})
  • MissingField.Ignore: Setting to ignore any fields which are missing, therefore avoiding an error

Find out about the MissingField options here:

Now, the Tables do not show errors.

Tables after ignore missing

Now let’s add all the columns to rename step:

= Table.TransformColumns(Custom1, {{"Data", each Table.RenameColumns(_,{{"Product","Item"},{"Division","Region"}}, MissingField.Ignore), type table}})
  • {{“Product”,”Item”},{“Division”,”Region”}}: This is a list of lists. Product is renamed to Item, and Division is renamed to Region. We can keep adding pairs of names in the same syntax.

Now the nested tables all have the same column headers.

Renamed columns - all the same

Rename columns from a table

It might become a little cumbersome to keep adding pairs of column names. Instead, we can use a separate table. This is what the FindReplace query is for.

To rename columns based on a table, we replace the list of renames with the List.Zip function containing the Table and column names (see example below).

= Table.TransformColumns(Custom1, {{"Data", each Table.RenameColumns(_,List.Zip({FindReplace[Find],FindReplace[Replace]}), MissingField.Ignore), type table}})

Combine data

Because all the tables have the same column names, we can remove unnecessary columns, then click the Expand icon and combine the data.



Dealing with nested tables containing different column names can be tricky in Power Query. But with the techniques in this post, you should be able to obtain consistent column names across all nested tables.

Related Posts:

Headshot Round

About the author

Hey, I’m Mark, and I run Excel Off The Grid.

My parents tell me that at the age of 7 I declared I was going to become a qualified accountant. I was either psychic or had no imagination, as that is exactly what happened. However, it wasn't until I was 35 that my journey really began.

In 2015, I started a new job, for which I was regularly working after 10pm. As a result, I rarely saw my children during the week. So, I started searching for the secrets to automating Excel. I discovered that by building a small number of simple tools, I could combine them together in different ways to automate nearly all my regular tasks. This meant I could work less hours (and I got pay raises!). Today, I teach these techniques to other professionals in our training program so they too can spend less time at work (and more time with their children and doing the things they love).

Do you need help adapting this post to your needs?

I'm guessing the examples in this post don't exactly match your situation. We all use Excel differently, so it's impossible to write a post that will meet everybody's needs. By taking the time to understand the techniques and principles in this post (and elsewhere on this site), you should be able to adapt it to your needs.

But, if you're still struggling you should:

  1. Read other blogs, or watch YouTube videos on the same topic. You will benefit much more by discovering your own solutions.
  2. Ask the 'Excel Ninja' in your office. It's amazing what things other people know.
  3. Ask a question in a forum like Mr Excel, or the Microsoft Answers Community. Remember, the people on these forums are generally giving their time for free. So take care to craft your question, make sure it's clear and concise.  List all the things you've tried, and provide screenshots, code segments and example workbooks.
  4. Use Excel Rescue, who are my consultancy partner. They help by providing solutions to smaller Excel problems.

What next?
Don't go yet, there is plenty more to learn on Excel Off The Grid.  Check out the latest posts:

Leave a Reply

Your email address will not be published. Required fields are marked *