Power Query
published
Search
K
Comment on page

Table.RenameColumns

Table.RenameColumns

Applies rename(s) of the form {old, new}.
function (table as table, renames as list, optional missingField as nullable any) as table

Description

Performs the given renames to the columns in table table. A replacement operation renames consists of a list of two values, the old column name and new column name, provided in a list. If the column doesn't exist, an exception is thrown unless the optional parameter missingField specifies an alternative (eg. MissingField.UseNull or MissingField.Ignore).

Category

Table.Column operations

Examples

Replace the column name "CustomerNum" with "CustomerID" in the table.
Table.RenameColumns(Table.FromRecords({[CustomerNum=1, Name="Bob", Phone = "123-4567"]}), {"CustomerNum", "CustomerID"})
Table.FromRecords({[CustomerID=1,Name="Bob", Phone="123-4567"]})
Replace the column name "CustomerNum" with "CustomerID" and "PhoneNum" with "Phone" in the table.
Table.RenameColumns(Table.FromRecords({[CustomerNum=1, Name="Bob", PhoneNum = "123-4567"]}), { {"CustomerNum", "CustomerID"}, {"PhoneNum", "Phone"} })
Table.FromRecords({[CustomerID=1,Name="Bob", Phone="123-4567"]})
Replace the column name "NewCol" with "NewColumn" in the table, and ignore if the column doesn't exist.
Table.RenameColumns(Table.FromRecords({[CustomerID=1, Name="Bob", Phone = "123-4567"]}), {"NewCol", "NewColumn"}, MissingField.Ignore)
Table.FromRecords({[CustomerID=1,Name="Bob", Phone="123-4567"]})