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

number — The 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"])
Output
Result
13

Example 2: Count fields in the first row of Sales

Output
Result
18

Example 3: Count the fields of differently shaped records

let
    Records = {
        [Name = "Alice", Email = "alice@example.com"],
        [Name = "Bob", Email = "bob@example.com", Phone = "555-0100"],
        [Name = "Charlie", Email = null]
    },
    Counts = List.Transform(Records, Record.FieldCount)
in
    Table.FromColumns(
        {List.Transform(Records, each [Name]), Counts},
        {"Name", "FieldCount"}
    )
Applied Steps

The final output — a table pairing each record's Name with its field count.

Name
FieldCount
1Alice2
2Bob3
3Charlie2

Compatibility

✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks
Contributors
kyleamueller