Table.RenameColumns
TableRenames one or more columns in a table.
Syntax
Table.RenameColumns(table as table, renames as list, optional missingField as nullable number) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The input table whose columns are to be renamed. |
renames | list | Yes | A list of rename pairs in the form {oldName, newName}, or a list of such pairs for multiple renames. |
missingField | number | No | Controls behavior when a specified column does not exist. Use MissingField.Error (default), MissingField.Ignore, or MissingField.UseNull. |
Return Value
table — A table with the specified columns renamed.
Remarks
Table.RenameColumns returns a new table with the specified columns renamed. The renames parameter accepts a list of two-item lists, where each inner list contains the old column name and the new column name.
To rename a single column, pass {"OldName", "NewName"}. To rename multiple columns, pass a list of pairs like {{"OldName1", "NewName1"}, {"OldName2", "NewName2"}}.
If a specified column does not exist, an error is raised by default. As a best practice, use the optional missingField parameter with MissingField.Ignore to prevent broken refreshes if upstream columns change.
If you have multiple rename steps in your query, consolidate them into a single Table.RenameColumns call with a list of pairs. Multiple separate rename steps add unnecessary overhead and make the query harder to maintain.
Examples
Example 1: Rename a single column
Table.RenameColumns(Sales, {"CustomerName", "Customer"})OrderID | Customer | Product | Category | UnitPrice | Quantity | OrderDate | Region | |
|---|---|---|---|---|---|---|---|---|
| 1 | 1 | Alice | Widget A | Widgets | 25 | 4 | 1/15/2024 | East |
| 2 | 2 | Bob | Gadget B | Gadgets | 50 | 2 | 1/18/2024 | West |
| 3 | 3 | Charlie | Widget C | Widgets | 15 | 10 | 2/1/2024 | East |
| 4 | 4 | Alice | Gadget D | Gadgets | 75 | 1 | 2/10/2024 | North |
| 5 | 5 | Diana | Widget A | Widgets | 25 | 6 | 3/5/2024 | West |
| 6 | 6 | Bob | Thingamajig E | Misc | 120 | 1 | 3/12/2024 | East |
| 7 | 7 | Charlie | Gadget B | Gadgets | 50 | 3 | 4/1/2024 | West |
| 8 | 8 | Diana | Widget C | Widgets | 15 | 8 | 4/15/2024 | North |
Example 2: Rename multiple columns
Table.RenameColumns(Sales, {{"UnitPrice", "Price"}, {"Quantity", "Qty"}})OrderID | CustomerName | Product | Category | Price | Qty | OrderDate | Region | |
|---|---|---|---|---|---|---|---|---|
| 1 | 1 | Alice | Widget A | Widgets | 25 | 4 | 1/15/2024 | East |
| 2 | 2 | Bob | Gadget B | Gadgets | 50 | 2 | 1/18/2024 | West |
| 3 | 3 | Charlie | Widget C | Widgets | 15 | 10 | 2/1/2024 | East |
| 4 | 4 | Alice | Gadget D | Gadgets | 75 | 1 | 2/10/2024 | North |
| 5 | 5 | Diana | Widget A | Widgets | 25 | 6 | 3/5/2024 | West |
| 6 | 6 | Bob | Thingamajig E | Misc | 120 | 1 | 3/12/2024 | East |
| 7 | 7 | Charlie | Gadget B | Gadgets | 50 | 3 | 4/1/2024 | West |
| 8 | 8 | Diana | Widget C | Widgets | 15 | 8 | 4/15/2024 | North |