Table.RenameColumns

This function is used to rename columns in a specified table. To perform a rename, you need to provide a list of two values for each replacement operation, which includes the old column name and the n...

Syntax

Table.RenameColumns(table as table, renames as list, optional missingField as nullable number) as table

About

This function is used to rename columns in a specified table. To perform a rename, you need to provide a list of two values for each replacement operation, which includes the old column name and the new column name. If the specified column does not exist in the table, an exception will be thrown unless the optional parameter "missingField" is used to specify an alternative action, such as using Null values or ignoring the missing field.

Explanation

Example 1 Alter the table's column name from "CustomerNum" to "CustomerID". Usage Power Query MTable.RenameColumns( Table.FromRecords({[CustomerNum = 1, Name = "Bob", Phone = "123-4567"]}), {"CustomerNum", "CustomerID"}) Output Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}) Example 2 Change the column names from "CustomerNum" to "CustomerID" and from "PhoneNum" to "Phone" in the table. Usage Power Query MTable.RenameColumns( Table.FromRecords({[CustomerNum = 1, Name = "Bob", PhoneNum = "123-4567"]}), { {"CustomerNum", "CustomerID"}, {"PhoneNum", "Phone"} }) Output Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}) Example 3 Modify the column name "NewCol" to "NewColumn" in the table, disregarding if the column does not exist. Usage Power Query MTable.RenameColumns( Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}), {"NewCol", "NewColumn"}, MissingField.Ignore) Output Table.FromRecords({[Custo