Record.ReorderFields
RecordReturns a new record with fields reordered according to the specified list. Fields not in the list follow after in their original order.
Syntax
Record.ReorderFields(record as record, fieldOrder as list, optional missingField as nullable number) as recordParameters
| Name | Type | Required | Description |
|---|---|---|---|
record | record | Yes | The source record. |
fieldOrder | list | Yes | A list of field name text values specifying the desired order. |
missingField | number | No | Controls behavior when a specified field does not exist: MissingField.Error (default), MissingField.Ignore, or MissingField.UseNull. |
Return Value
record — A new record with fields in the specified order.
Remarks
Record.ReorderFields returns a new record with fields placed in the order specified by fieldOrder. Fields not listed in fieldOrder are appended at the end, maintaining their original relative order from the source record. Field names and values are unchanged.
Record field order matters in Power Query because it affects the column order when records are expanded into table columns, and the order in which fields appear in Record.ToTable output. Record.ReorderFields is the record-level equivalent of Table.ReorderColumns.
The optional missingField parameter controls behavior when a name in fieldOrder does not exist in the record:
- MissingField.Error (default, 0) — raises an error
- MissingField.Ignore (1) — skips missing names silently
- MissingField.UseNull (2) — inserts the specified field with a null value
A common pattern is to reorder fields before converting a record to a table with Record.ToTable or before using Table.FromRecords, to control the column order of the resulting table.
Examples
Example 1: Reorder all fields explicitly
Record.ReorderFields(
[City = "New York", Name = "Alice", Age = 30],
{"Name", "Age", "City"}
)Name | Age | City | |
|---|---|---|---|
| 1 | Alice | 30 | New York |
Example 2: Unlisted fields are appended at the end in original order
Record.ReorderFields(
[D = 4, A = 1, C = 3, B = 2],
{"A", "B"}
)A | B | D | C | |
|---|---|---|---|---|
| 1 | 1 | 2 | 4 | 3 |
Example 3: Reorder a Sales row to put OrderID and CustomerName first
let
Row = Sales{0},
Reordered = Record.ReorderFields(Row, {"OrderID", "CustomerName", "Product"})
in
Record.ToTable(Reordered)The final output — converts the reordered record to a two-column Name/Value table showing the new field order.
Name | Value | |
|---|---|---|
| 1 | OrderID | 1 |
| 2 | CustomerName | Alice |
| 3 | Product | Widget A |
| 4 | Category | Widgets |
| 5 | UnitPrice | 25 |
| 6 | Quantity | 4 |
| 7 | OrderDate | 2024-01-15 |
| 8 | Region | East |