Record.RenameFields

Updated on

Record.RenameFields is a Power Query M function that renames fields in a record to the new field names specified in a list. The function returns a new record with the fields renamed according to the provided renames list.

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

Syntax

Record.RenameFields(
   record as record,
   renames as list,
   optional missingField as nullable number,
) as record
Argument Attribute Description
record
renames
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.RenameFields applies new names to existing fields in a record based on a list of rename pairs provided in renames. For multiple renames, a list of such pairs is used to update the record’s field names accordingly. In case the specified field does not exist, the function returns an error by default. You can change this behavior by providing an optional MissingField.Type.

Examples

Rename the field “UnitPrice” to “Price” from the record.

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

Rename the fields “UnitPrice” to “Price” and “OrderNum” to “OrderID” from the record.

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

Other functions related to Record.RenameFields are:

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