top of page

You are learning Power Query in MS Excel

How to rename columns in Power Query?

There are three main ways to rename columns in Power Query:

1. Manual Renaming:

* This is the simplest method for renaming a single column at a time.
* Select the column header you want to rename.
* There are three options to access the rename functionality:
* Double-click directly on the column header.
* Right-click on the header and choose "Rename" from the context menu.
* Go to the "Transform" tab and select "Rename" under the "Any Column" group.
* Enter your desired new name for the column and press Enter.

2. Using Table.RenameColumns Function:

* This method is more efficient for renaming multiple columns at once.
* In the formula bar, type the following formula, replacing "OldColumnName1", "NewColumnName1", "OldColumnName2", and "NewColumnName2" with your actual column names and desired new names:

```
Table.RenameColumns(YourTable,
{ {"OldColumnName1", "NewColumnName1"}, {"OldColumnName2", "NewColumnName2"} })
```

* "YourTable" represents the name of your table.
* You can add more name pairs within curly braces for additional renames (e.g., {"OldColumnName3", "NewColumnName3"}).

3. Using List.Zip with Table.TransformColumns:

* This method offers more flexibility for renaming columns based on patterns or logic. It's suitable for advanced users.

* Here's a general outline, but you'll need to customize the inner logic based on your specific renaming needs:

```
let
NewColumnNameList = List.Zip({YourTable.ColumnNames}, List.Transform({YourTable.ColumnNames}, (OldName) => YourRenamingLogic(OldName)))
in
Table.TransformColumns(YourTable, List.Zip(NewColumnNameList, YourTable.ColumnNames))
```

Choosing the Right Method:

* For simple renames of one or two columns, manual renaming is the easiest option.
* If you need to rename multiple columns with a consistent pattern, the `Table.RenameColumns` function is efficient.
* For complex renaming logic or dynamic name generation, `List.Zip` with `Table.TransformColumns` offers the most flexibility.

bottom of page