Skip to content

Renaming Table Column Headings

This page shows how to rename all of a table’s column headings in one step, rather than one column at a time.

Sometimes the columns of an existing table need new names. A common case is a model that compares order dates with delivery dates. It needs two calendar tables that can be filtered separately, and their columns are easier to tell apart if one table’s headings start with Order and the other’s with Delivery.

The prefixes could be typed into each heading by hand, but the renaming can be automated instead. There are two ways to do it, and both use M, the language behind Power Query.

1. Make a copy of the Order Calendar query

Section titled “1. Make a copy of the Order Calendar query”

The starting point is an Order Calendar query like this one:

The Order Calendar query in the Power Query editor, with columns Day, Date, Week of Year and Week of Month, and Applied Steps that add each calendar column in turn

  • In the Queries pane on the left, right-click Order Calendar and choose Reference.

The right-click menu on the Order Calendar query, with Reference highlighted

This creates a new query, Order Calendar (2), which starts from the output of Order Calendar.

The Queries pane listing Order Calendar and Order Calendar (2)

  • Rename the new query to Delivery Calendar.

The Queries pane listing Order Calendar and Delivery Calendar

The new query’s headings are the ones to rename.

  • In the Delivery Calendar query, click the fx button beside the formula bar to add a step, and enter this formula:
= Table.ColumnNames(Source)

The step returns a list of the table’s column headings.

A list of the calendar’s eleven column headings, from Day and Date to Quarter and Day of Year

  • Click To Table on the Transform tab to turn the list into a table.

The headings as a one-column table, with the column named Column1

  • Add a custom column with the formula below, which puts Del and a space in front of each heading:

The Custom Column dialog creating a column called Custom with the formula “Del “ & [Column1]

The table now has each old heading beside its new one.

A two-column table pairing each heading in Column1 with its new name in Custom, such as Day with Del Day

  • Turn the table into a list of lists by wrapping the custom column step’s formula in Table.ToRows, like this:
= Table.ToRows(Table.AddColumn(#"Converted to Table", "Custom", each "Del " & [Column1]))

The step now returns a list with one item per heading, and each item is itself a list holding the old name and the new one.

A list of eleven List values, with a preview of the first showing Day and Del Day

3. Rename the columns from the list of lists

Section titled “3. Rename the columns from the list of lists”
  • Rename this step to ListOfLists in Applied Steps.

Applied Steps for Delivery Calendar, reading Source, Custom1, Converted to Table and ListOfLists

  • Add one more step with this formula:
= Table.RenameColumns(Source, ListOfLists)

Table.RenameColumns takes the original table from the Source step and renames each column according to its pair in the list. Every heading now starts with Del:

The Delivery Calendar query after the rename, with columns Del Day, Del Date, Del Week of Year and Del Week of Month

There is a quicker way, though it is less flexible. The list-of-lists method can take its pairs of names from anywhere, such as a mapping table kept in Excel, whereas this one applies the same change to every heading.

Add this formula as the step straight after Source:

= Table.TransformColumnNames(Source, each "Del " & _)

It gives the same result in a single step, with Del in front of every column heading.