OpenBI Docs Buy

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
ParameterTypeDescription
recordrecordThe record to work on.
fieldNametextThe new field's name; it must not be in the record already.
valueanyThe new field's value.
delayednullable 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, or Record.Combine with 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]

Record.Combine, Record.RemoveFields, Record.TransformFields, Table.AddColumn.

Last updated · OpenBI Studio 0.3.79