Record.TransformFields

Updated on

Record.TransformFields is a Power Query M function that applies specified transformations to a record’s fields. The function returns a modified record after applying the transformations.

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

Syntax

Record.TransformFields(
   record as record,
   transformOperations as list,
   optional missingField as nullable number,
) as record
Argument Attribute Description
record
transformOperations
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.TransformFields updates a record by applying a series of transformations specified in transformOperations. Each operation pairs a field name with a function that modifies the field’s value. This can be done for one or many fields simultaneously. 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

Convert “Price” field to number.

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

Convert “OrderID” and “Price” fields to numbers.

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

Other functions related to Record.TransformFields are:

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