OpenBI Docs Buy

Table.TransformColumnNames

Renames every column with a function of its name.

Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

Table.TransformColumnNames(table as table, nameGenerator as function, optional options as nullable record) as table
ParameterTypeDescription
tabletableThe table whose columns to rename.
nameGeneratorfunctionA function of a column's name (text) that gives its new name.
optionsnullable record
optional
Options for the new names: MaxLength cuts each name to that many characters; Comparer says when two names are the same (Comparer.Ordinal when left out).

Returns

table. The same rows and columns, under the new names.

Remarks

  • Handy for names from a file: trim them, take out spaces or change their case in one step.
  • Two columns that would get the same name are kept apart: the later one gets a number, as PRODUCT and PRODUCT1, and with MaxLength the number fits within the length.

Examples

Names in title case

Table.TransformColumnNames(#table({"product name", "unit price"}, {{"Chair", 50}}), Text.Proper)
Product NameUnit Price
Chair50

Without spaces

Table.TransformColumnNames(#table({"Product Name", "Unit Price"}, {{"Chair", 50}}), each Text.Replace(_, " ", ""))
ProductNameUnitPrice
Chair50

Short names that would clash

Table.TransformColumnNames(#table({"Unit Price", "Unit Cost"}, {{50, 30}}), each _, [MaxLength = 4])
UnitUni1
5030

Both names cut to four letters would be Unit: the second becomes Uni1.

Table.RenameColumns, Table.PrefixColumns, Text.Proper, Text.Trim.

Last updated · OpenBI Studio 0.3.79