Record.TransformFields

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

Description

Returns a record after applying transformations specified in list transformOperations to record. One or more fields may be transformed at a given time.

In the case of a single field being transformed, transformOperations is expected to be a list with two items. The first item in transformOperations specifies a field name, and the second item in transformOperations specifies the function to be used for transformation. For example, {"Quantity", Number.FromText}
In the case of a multiple fields being transformed, transformOperations is expected to be a list of lists, where each inner list is a pair of field name and transformation operation. For example, {{"Quantity",Number.FromText},{"UnitPrice", Number.FromText}}

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:

BI Gorilla Youtube Channel

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