Table.ReorderColumns
Puts the columns in the order you list them.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.ReorderColumns(table as table, columnOrder as list, optional missingField as nullable number) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table whose columns to reorder. |
columnOrder | list | Column names in the order you want. |
missingField | nullable number optional | What to do with a name that isn't a column: MissingField.Error (the default), MissingField.Ignore (leave it out) or MissingField.UseNull (add it as a column of nulls, in its place). |
Returns
table. The same columns and rows, in the new column order.
Remarks
- Transform data writes the whole list of columns when you drag one. A column left out of the list is kept, not removed.
Examples
A new order for every column
Table.ReorderColumns(#table({"Price", "Product", "Shop"}, {{50, "Chair", "Oslo"}}), {"Shop", "Product", "Price"})
| Shop | Product | Price |
|---|---|---|
| Oslo | Chair | 50 |
Two neighbours swapped
Table.ReorderColumns(#table({"Product", "Price", "Shop"}, {{"Chair", 50, "Oslo"}}), {"Shop", "Price"})
| Product | Shop | Price |
|---|---|---|
| Chair | Oslo | 50 |
A column that may not be there yet
Table.ReorderColumns(#table({"Product", "Price"}, {{"Chair", 50}}), {"Shop", "Price", "Product"}, MissingField.UseNull)
| Shop | Price | Product |
|---|---|---|
| null | 50 | Chair |
Related functions
Table.SelectColumns, Table.ColumnNames, Table.RenameColumns.