Record.HasFields

Record

Returns true if a record contains all of the specified field names.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Record.HasFields(record as record, fields as any) as logical

Parameters

NameTypeRequiredDescription
recordrecordYesThe record to check.
fieldsanyYesA single field name as text, or a list of field name text values to check.

Return Value

logicalTrue if all specified fields exist in the record, false otherwise.

Remarks

Record.HasFields checks whether a record contains all of the specified field names. Pass a single text value to check for one field, or a list of text values to require that all listed fields are present (AND logic — all-or-nothing). If any one field is absent, the function returns false.

This is the preferred alternative to wrapping field access in try/otherwise for schema checks. It is useful for:

- Defensive coding: verifying fields exist before accessing them with [FieldName] syntax - Schema validation: confirming that records from semi-structured sources (JSON, API responses) have the expected shape - Conditional branching: routing records to different transformation paths based on their structure

To check whether any of a list of fields is present (OR logic), combine with List.AnyTrue: ``powerquery List.AnyTrue(List.Transform({"Email", "Phone"}, each Record.HasFields(record, _))) ``

Examples

Example 1: Check for a single field that exists

Record.HasFields([Name = "Alice", Age = 30], "Name")
Result
Result
1TRUE

Example 2: Check for multiple fields — returns false if any are missing

Record.HasFields([Name = "Alice", Age = 30], {"Name", "Email"})
Result
Result
1FALSE

Example 3: Use as a gate before accessing an optional field per Sales row

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(Sales, 4), {"OrderID", "CustomerName", "UnitPrice"}),
    "FinalPrice",
    each if Record.HasFields(_, "Discount")
         then [UnitPrice] * (1 - [Discount])
         else [UnitPrice],
    type number
)
Result
OrderID
CustomerName
UnitPrice
FinalPrice
11Alice2525
22Bob5050
33Charlie1515
44Alice7575

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks