Table.TransformColumnNames

The process of modifying column names is achieved by employing the designated nameGenerator function. Users can specify the maximum length of the new column names by using the MaxLength option. If the...

Syntax

Table.TransformColumnNames(table as table, nameGenerator as function, optional options as nullable record) as table

About

The process of modifying column names is achieved by employing the designated nameGenerator function. Users can specify the maximum length of the new column names by using the MaxLength option. If the output of the function results in a longer column name than the specified MaxLength, the lengthy name will be truncated. The Comparer parameter is utilized to manage the comparison method when generating new column names. Comparers can be utilized to facilitate case-insensitive comparisons or comparisons that are cognizant of culture and locale. The formula language offers the following pre-built comparers: - Comparer.Ordinal: Utilized for exact ordinal comparisons. - Comparer.OrdinalIgnoreCase: Utilized for exact ordinal case-insensitive comparisons. - Comparer.FromCulture: Employed for culture-aware comparisons.

Explanation

Example 1 Eliminate the #(tab) character from the names of columns. Usage: In Power Query M language, use the MTable.TransformColumnNames function to remove the #(tab) character from the column names. For example, apply it to a table created with Table.FromRecords function where one of the columns is named "Col#(tab)umn". This will result in an output table where the column name is simplified to "Column". Example 2 Change column names to create case-insensitive names that are a maximum of 6 characters long. Usage: In Power Query M language, use the MTable.TransformColumnNames function to modify column names to be case-insensitive and ensure they are no longer than 6 characters. This can be applied to a table, like the one generated by Table.FromRecords function with columns named "ColumnNum", "cOlumnnum", and "coLumnNUM". The output table will have updated column names such as "Column" for the first column, "cOlum1" for the second column, and "coLum2" for the third column.