Record.ReorderFields
A record with the fields you name put in the order you give.
Group: Record. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Record.ReorderFields(record as record, fieldOrder as list, optional missingField as nullable number) as record
| Parameter | Type | Description |
|---|---|---|
record | record | The record to work on. |
fieldOrder | list | The field names in their new order. |
missingField | nullable number optional | What to do with a field name the record doesn't have: MissingField.Error (the default), MissingField.Ignore (skip it) or MissingField.UseNull (add it as a field of null). |
Returns
record. The same fields and values in the new order.
Examples
Every field named
Record.ReorderFields([Total = 120, Shop = "Oslo", Order = 1001], {"Order", "Shop", "Total"})
[Order = 1001, Shop = "Oslo", Total = 120]
Two fields swapped
Record.ReorderFields([Shop = "Oslo", Order = 1001, Total = 120], {"Order", "Shop"})
[Order = 1001, Shop = "Oslo", Total = 120]
Total, not in the list, keeps its place at the end.
A field the record lacks, added
Record.ReorderFields([Order = 1001, Shop = "Oslo"], {"Shop", "Order", "Note"}, MissingField.UseNull)
[Shop = "Oslo", Order = 1001, Note = null]
Related functions
Record.SelectFields, Record.RenameFields, Table.ReorderColumns.