Record.ReorderFields

Updated on

Record.ReorderFields is a Power Query M function that reorders the fields in a record based on the specified field order. The function returns a new record with the fields reordered, maintaining their values and leaving unspecified fields in their original positions.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Record.ReorderFields(
   record as record,
   fieldOrder as list,
   optional missingField as nullable number,
) as record
Argument Attribute Description
record
fieldOrder
missingField optional The MissingField.Type determines the function’s reaction to operations on missing columns. When omitted, it uses MissingField.Error and generates an error for missing columns. Alternatives include MissingField.UseNull, substituting null for missing columns, and MissingField.Ignore, which ignores missing columns.

Description

Record.ReorderFields adjusts the sequence of fields within a record according to a new specified order given in fieldOrder. It rearranges the fields without changing their corresponding values, and fields not mentioned remain in their original sequence. In case a specified field does not exist, the function returns an error by default. You can change this behavior by providing an optional MissingField.Type.

Examples

Reorder some of the fields in the record.

// Output: [OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0]
Record.ReorderFields( 
    [CustomerID = 1, OrderID = 1, Item = "Fishing rod", Price = 100.0],
    {"OrderID", "CustomerID"}
 )

Other functions related to Record.ReorderFields are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/record-reorderfields