Record.Field
The value of a record's field by its name, a name that may be worked out in the query.
Group: Record. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Record.Field(record as record, field as text) as any
| Parameter | Type | Description |
|---|---|---|
record | record | The record to work on. |
field | text | The field's name. |
Returns
any. The field's value; an error when the record has no such field.
Remarks
Record.Field(r, "Shop")is the same asr[Shop]; the function is for names held in a variable or a column.- For a field that may be missing,
Record.FieldOrDefaultgives a value of your choice instead of an error.
Examples
A field by name
Record.Field([Order = 1001, Shop = "Oslo"], "Shop")
"Oslo"
A name chosen in the query
let
Order = [Order = 1001, Jan = 120, Feb = 90],
Month = "Feb"
in
Record.Field(Order, Month)
90
A missing field
Record.Field([Order = 1001, Shop = "Oslo"], "Discount")
Result: an error.
[Reason = "Expression.Error", Message = "The field 'Discount' of the record wasn't found.", Detail = null]
Related functions
Record.FieldOrDefault, Record.HasFields, Record.SelectFields.