OpenBI Docs Buy

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
ParameterTypeDescription
recordnullable recordThe record to read.
fieldtextThe field's name.
defaultValueany
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

Record.Field, Record.HasFields.

Last updated · OpenBI Studio 0.3.79