Table.TransformColumnNames
Table function · By Tahir Nas · Examples run in our simulator · Published · Updated
Applies a function to every column name.
When to use it
Use it to apply one rule to every column name, such as trimming spaces, fixing case or removing a prefix. Unlike a rename list, it also covers columns the source adds later.
Syntax
Table.TransformColumnNames(table as table, nameGenerator as function, optional options as nullable record) as tableParameters
- nameGenerator
- A function from old name to new name.
Returns
The table with renamed columns.
Example
Table.TransformColumnNames(#table({" order id", "QTY "}, {{1, 2}}), each Text.Proper(Text.Trim(_)))Result
| Order Id | Qty |
|---|---|
| 1 | 2 |
Example: remove a prefix after expanding
Text.Replace strips the prefix that an expand step added.
Table.TransformColumnNames(#table({"Customer.Name", "Customer.City"}, {{"Ana", "Porto"}}), each Text.Replace(_, "Customer.", ""))Result
| Name | City |
|---|---|
| Ana | Porto |
Both results are produced by the Power Query Exercises simulator, an independent implementation of a documented subset of M, and checked on every build.
Good to know
- Covers columns added later, unlike a fixed rename list.
Common mistakes
- Producing duplicate names (two columns trimmed to the same text).
- Using it where only one column needs a new name.
Exercises that use Table.TransformColumnNames
Learn more
Related functions
Official documentation: Table.TransformColumnNames on Microsoft Learn.