Record.RenameFields

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

Returns a record after renaming fields in the input record to the new field names specified in list renames. For multiple renames, a nested list can be used ({ {old1, new1}, {old2, new2} }.

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:

BI Gorilla Youtube Channel

Last update: December 1, 2023 | Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/record-renamefields
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.