Record.TransformFields
A record with some fields' values changed by functions you give, one function per field.
Group: Record. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Record.TransformFields(record as record, transformOperations as list, optional missingField as nullable number) as record
| Parameter | Type | Description |
|---|---|---|
record | record | The record to work on. |
transformOperations | list | One pair {name, function}, or a list of pairs {{name, function}, ...}; each function gets the field's value and gives the new one. |
missingField | nullable number optional | What to do with a field name the record doesn't have: MissingField.Error (the default), MissingField.Ignore (skip it) or MissingField.UseNull (add it as a field of null). |
Returns
record. The record with the new values; names and order are kept.
Examples
A price with 25 % VAT
Record.TransformFields([Product = "chair", Price = 40], {"Price", each _ * 1.25})
[Product = "chair", Price = 50]
Two fields
Record.TransformFields([Product = "chair", Price = 40], {{"Product", Text.Proper}, {"Price", each _ * 1.25}})
[Product = "Chair", Price = 50]
A field that may be missing
Record.TransformFields([Product = "chair", Price = 40], {{"Price", each _ * 1.25}, {"Discount", each _ / 2}}, MissingField.Ignore)
[Product = "chair", Price = 50]
With MissingField.UseNull the record would get Discount too, its function given null.
Related functions
Record.AddField, Record.RenameFields, Table.TransformColumns.