Record.FieldOrDefault
The value of a record's field by name, or a default when the record has no such field.
Group: Record. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Record.FieldOrDefault(record as nullable record, field as text, optional defaultValue as any) as any
| Parameter | Type | Description |
|---|---|---|
record | nullable record | The record to read. |
field | text | The field's name. |
defaultValue | any optional | What comes back when the field is missing. Left out, null. |
Returns
any. The field's value, or the default.
Remarks
- A field that exists but holds null gives null, not the default.
- A null record has no fields, so it gives the default: handy after a lookup that found nothing.
Examples
A discount that most orders don't have
Record.FieldOrDefault([Order = 1001, Shop = "Oslo"], "Discount", 0)
0
The field is there
Record.FieldOrDefault([Order = 1001, Shop = "Oslo"], "Shop", "none")
"Oslo"
No default
Record.FieldOrDefault([Order = 1001, Shop = "Oslo"], "Discount")
null