Table.TransformColumnNames Function in Power Query

The Table.TransformColumnNames function transforms column names by using the given function.

Syntax

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

The function has the following parameters:
1. table – The input table whose column names need to be transformed.
2. nameGenerator – A function that takes a column name as input and returns the modified column name.
3. options: It is an optional parameter. A record that can contain additional settings such as locale handling.

Example:

Power Query M

let
  MyTable = Table.FromRecords(
    {
      [CustomerID = 1, Name = "Ashish", Phone = "123-4567"], 
      [CustomerID = 2, Name = "Katrina", Phone = "987-6543"], 
      [CustomerID = 3, Name = "Alia", Phone = "543-7890"], 
      [CustomerID = 4, Name = "Vicky", Phone = "676-8479"], 
      [CustomerID = 5, Name = "Mohini", Phone = "574-8864"], 
      [CustomerID = 6, Name = "Meenakshi", Phone = "574-8864"], 
      [CustomerID = 7, Name = "Esha", Phone = "574-8864"], 
      [CustomerID = 8, Name = "Anjali", Phone = "574-8864"]
    }
  ),

Return = Table.TransformColumnNames(MyTable, each _ & "--Myprefix")
in
    Return  

The output of the above code is shown below:

Table.TransformColumnNames function in Power Query

Example: Convert Column Names to Lowercase.

Power Query M

let
  MyTable = Table.FromRecords(
    {
      [CustomerID = 1, Name = "Ashish", Phone = "123-4567"], 
      [CustomerID = 2, Name = "Katrina", Phone = "987-6543"], 
      [CustomerID = 3, Name = "Alia", Phone = "543-7890"], 
      [CustomerID = 4, Name = "Vicky", Phone = "676-8479"], 
      [CustomerID = 5, Name = "Mohini", Phone = "574-8864"], 
      [CustomerID = 6, Name = "Meenakshi", Phone = "574-8864"], 
      [CustomerID = 7, Name = "Esha", Phone = "574-8864"], 
      [CustomerID = 8, Name = "Anjali", Phone = "574-8864"]
    }
  ),
    Return = Table.TransformColumnNames(MyTable, each Text.Lower(_))
in
    Return 

The output of the above code is shown below:

Table.TransformColumnNames function in Power Query