Power QueryExercises

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 table

Parameters

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 IdQty
12

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

NameCity
AnaPorto

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

Common mistakes

Exercises that use Table.TransformColumnNames

Learn more

Related functions

Official documentation: Table.TransformColumnNames on Microsoft Learn.