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 incolumnOrderis not in the table. UseMissingField.Ignoreto skip it orMissingField.UseNullto 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:
| MemberID | Plan | MonthlyFee |
|---|---|---|
| GYM-101 | Basic | 29 |
| GYM-102 | Plus | 49 |
| GYM-103 | Elite | 79 |
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:
| Plan | MemberID | MonthlyFee |
|---|---|---|
| Basic | GYM-101 | 29 |
| Plus | GYM-102 | 49 |
| Elite | GYM-103 | 79 |
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:
| Code | ClassName | Trainer | Capacity |
|---|---|---|---|
| CL-A1 | Spin | Maya | 20 |
| CL-B2 | Yoga | Devon | 15 |
| CL-C3 | HIIT | Priya | 25 |
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:
| Trainer | Code | ClassName | Capacity |
|---|---|---|---|
| Maya | CL-A1 | Spin | 20 |
| Devon | CL-B2 | Yoga | 15 |
| Priya | CL-C3 | HIIT | 25 |
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:
| SKU | Product | Qty |
|---|---|---|
| SP-501 | Protein Bar | 3 |
| SP-502 | Shaker | 1 |
| SP-503 | Towel | 2 |
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:
| Product | SKU | Qty |
|---|---|---|
| Protein Bar | SP-501 | 3 |
| Shaker | SP-502 | 1 |
| Towel | SP-503 | 2 |
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:
| CoachID | Name | Specialty |
|---|---|---|
| CO-11 | Lena | Strength |
| CO-12 | Raj | Cardio |
| CO-13 | Tomas | Mobility |
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:
| Name | Region | CoachID | Specialty |
|---|---|---|---|
| Lena | null | CO-11 | Strength |
| Raj | null | CO-12 | Cardio |
| Tomas | null | CO-13 | Mobility |
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:
| AssetTag | Item | Location |
|---|---|---|
| EQ-A | Treadmill | Floor 1 |
| EQ-B | Rower | Floor 2 |
| EQ-C | Bench | Floor 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:
| Location | Item | AssetTag |
|---|---|---|
| Floor 1 | Treadmill | EQ-A |
| Floor 2 | Rower | EQ-B |
| Floor 1 | Bench | EQ-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 aTrainercolumn, and withoutMissingField.Ignoreit raises an error. - With no
missingField, a name that does not exist throws. The message readsExpression.Error: The column 'Discount' of the table wasn't found.AddMissingField.IgnoreorMissingField.UseNullto 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: