Table.ReorderColumns Function (Power Query M)

Table.ReorderColumns returns a table with its columns rearranged into the order you specify. Available in Excel (Power Query), Power BI Desktop, and Power BI Service.

If you want to move columns around in a query, putting a key field first or matching a layout you need downstream, this is the function that does it. You pass the table and a list of column names in the order you want, and it hands back the same data with the columns reshuffled.

Syntax of Table.ReorderColumns Function

Table.ReorderColumns(table as table, columnOrder as list, optional missingField as nullable number) as table

where

  • table (required, table). The table whose columns you want to reorder.
  • columnOrder (required, list). A list of column names, written in the order you want them to appear.
  • missingField (optional, nullable number). Controls what happens when a name in columnOrder is not in the table. Use MissingField.Ignore to skip it or MissingField.UseNull to add it as a blank column. Omit it and a missing name raises an error.

Returns: a table with the same rows and data, but with columns ordered according to columnOrder. Any column not named in the list keeps its original position.

In plain terms, you list the columns in the order you want, and you get the table back with those columns moved into that order.

Example 1: Swap two columns

Put the Plan column before MemberID in a small membership table.

Here is the starting data:

MemberIDPlanMonthlyFee
GYM-101Basic29
GYM-102Plus49
GYM-103Elite79

List the columns in the order you want them:

let
Source = Excel.CurrentWorkbook(){[Name="Members"]}[Content],
Result = Table.ReorderColumns(Source,{"Plan","MemberID","MonthlyFee"})
in
Result

The result is:

PlanMemberIDMonthlyFee
BasicGYM-10129
PlusGYM-10249
EliteGYM-10379

The data is untouched. Only the column order changed to match the list you passed.

Example 2: Move one column to the front

Here the goal is to pull Trainer to the front while leaving the rest as they are.

Here is the starting data:

CodeClassNameTrainerCapacity
CL-A1SpinMaya20
CL-B2YogaDevon15
CL-C3HIITPriya25

To truly move Trainer first, name it and then list the remaining columns:

let
Source = Excel.CurrentWorkbook(){[Name="Classes"]}[Content],
Result = Table.ReorderColumns(Source,{"Trainer","Code","ClassName","Capacity"})
in
Result

The result is:

TrainerCodeClassNameCapacity
MayaCL-A1Spin20
DevonCL-B2Yoga15
PriyaCL-C3HIIT25

A partial list like {"Trainer"} would not move anything noticeable, because unlisted columns keep their spots. Spelling out every column after Trainer is what forces it to the front.

Example 3: Ignore a missing column

You have an order list and want Product first, then SKU, but the list also names a Discount column that does not exist here.

Here is the starting data:

SKUProductQty
SP-501Protein Bar3
SP-502Shaker1
SP-503Towel2

Pass MissingField.Ignore so the missing name is skipped instead of throwing:

let
Source = Excel.CurrentWorkbook(){[Name="Orders"]}[Content],
Result = Table.ReorderColumns(Source,{"Product","Discount","SKU"},MissingField.Ignore)
in
Result

The result is:

ProductSKUQty
Protein BarSP-5013
ShakerSP-5021
TowelSP-5032

Discount is dropped from the order silently. Qty was not in the list, so it stays where it was.

Example 4: Add a missing column with UseNull

Same idea as before, but this time you want the missing Region column to actually appear as a blank column.

Here is the starting data:

CoachIDNameSpecialty
CO-11LenaStrength
CO-12RajCardio
CO-13TomasMobility

Pass MissingField.UseNull so Region is created and filled with nulls:

let
Source = Excel.CurrentWorkbook(){[Name="Coaches"]}[Content],
Result = Table.ReorderColumns(Source,{"Name","Region","CoachID","Specialty"},MissingField.UseNull)
in
Result

The result is:

NameRegionCoachIDSpecialty
LenanullCO-11Strength
RajnullCO-12Cardio
TomasnullCO-13Mobility

Region lands in the position you listed it, as a new column full of null. This is handy when you need a fixed column layout even if a source is missing a field. If you instead want a new column with computed values, use Table.AddColumn.

Example 5: Reverse all columns

When you do not know the column names ahead of time, you can build the order list dynamically.

Here is the starting data:

AssetTagItemLocation
EQ-ATreadmillFloor 1
EQ-BRowerFloor 2
EQ-CBenchFloor 1

Grab the column names with Table.ColumnNames, flip the list with List.Reverse, and feed that in:

let
Source = Excel.CurrentWorkbook(){[Name="Equipment"]}[Content],
Cols = Table.ColumnNames(Source),
Reversed = List.Reverse(Cols),
Result = Table.ReorderColumns(Source,Reversed)
in
Result

The result is:

LocationItemAssetTag
Floor 1TreadmillEQ-A
Floor 2RowerEQ-B
Floor 1BenchEQ-C

Because the list covers every column, the whole table flips order without you hard-coding a single name.

Things to keep in mind with Table.ReorderColumns

  • Column names are case-sensitive. "trainer" will not match a Trainer column, and without MissingField.Ignore it raises an error.
  • With no missingField, a name that does not exist throws. The message reads Expression.Error: The column 'Discount' of the table wasn't found. Add MissingField.Ignore or MissingField.UseNull to handle it.
  • It only changes column order. No column is renamed, dropped, or recalculated, so the row values stay exactly the same. To reorder rows instead, use Table.Sort.

Performance and query folding

Reordering columns is a metadata-only operation, so it is cheap and folds trivially against sources that support folding, such as SQL Server. On Excel, CSV, or folder sources it runs locally, which is no problem since no data is actually moved.

Common questions about Table.ReorderColumns

What is the difference between Table.ReorderColumns and Table.SelectColumns?

Table.ReorderColumns keeps every column and only changes their order. Table.SelectColumns keeps the subset you name and drops the rest, so reach for it when you want to remove columns rather than rearrange them.

List of All Power Query Functions

Related Power Query Functions / Articles:

I am a huge fan of Microsoft Excel and love sharing my knowledge through articles and tutorials. I work as a business analyst and use Microsoft Excel extensively in my daily tasks. My aim is to help you unleash the full potential of Excel and become a data-slaying wizard yourself.