Record.AddField
A record with one more field, added at the end.
Group: Record. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Record.AddField(record as record, fieldName as text, value as any, optional delayed as nullable logical) as record
| Parameter | Type | Description |
|---|---|---|
record | record | The record to work on. |
fieldName | text | The new field's name; it must not be in the record already. |
value | any | The new field's value. |
delayed | nullable logical optional | true when the value is a function of no arguments whose answer is the field's value, worked out only when the field is read. |
Returns
record. The record with the new field last.
Remarks
- To change a field that is already there, use
Record.TransformFields, orRecord.Combinewith a record that has the new value. - With delayed true the field holds the function's answer, not the function: it is worked out when the field is first read.
Examples
A status on an order
Record.AddField([Order = 1001, Shop = "Oslo"], "Status", "Shipped")
[Order = 1001, Shop = "Oslo", Status = "Shipped"]
A field that exists already
Record.AddField([Order = 1001, Shop = "Oslo"], "Shop", "Bergen")
Result: an error.
[Reason = "Expression.Error", Message = "The field 'Shop' already exists in the record.", Detail = null]
A total worked out when it is read
Record.AddField([Price = 40, Units = 3], "Total", () => 40 * 3, true)
[Price = 40, Units = 3, Total = 120]
Related functions
Record.Combine, Record.RemoveFields, Record.TransformFields, Table.AddColumn.