Record.FieldCount

Record

Returns the number of fields in a record.

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

Syntax

Record.FieldCount(record as record) as number

Parameters

NameTypeRequiredDescription
recordrecordYesThe record whose field count is returned.

Return Value

numberThe number of fields in the record.

Remarks

Record.FieldCount returns the number of fields in a record. It is equivalent to List.Count(Record.FieldNames(record)). The function accepts any record, including table rows accessed with table{n}.

Common uses:

- Schema validation: confirm a record has the expected number of fields before processing - Dynamic introspection: count fields when the record structure is not known at query design time (e.g., semi-structured JSON data) - Conditional logic: branch based on whether a record has been enriched with additional fields

Note that Record.FieldCount does not accept null — it raises an error if passed null. Use the null-coalescing operator ?? to handle potentially-null records safely: Record.FieldCount(record ?? []).

Examples

Example 1: Count fields in a literal record

Record.FieldCount([Name = "Alice", Age = 30, City = "New York"])
Result
Result
13

Example 2: Count fields in the first row of Sales

Record.FieldCount(Sales{0})
Result
Result
18

Example 3: Add a field count column to a table of records

let
    Data = Table.FromRecords({
        [A=1, B=2, C=3],
        [A=1, B=2, C=3, D=4],
        [A=1, B=2]
    }),
    WithCount = Table.AddColumn(
        Data, "FieldCount", each Record.FieldCount(_), type number
    )
in
    WithCount
Result
A
B
C
D
FieldCount
1123null3
212344
312nullnull2

Compatibility

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