Record.FieldCount
RecordReturns the number of fields in a record.
Syntax
Record.FieldCount(record as record) as numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
record | record | Yes | The 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 | |
|---|---|
| 1 | 3 |
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 | |
|---|---|---|
| 1 | Alice | 2 |
| 2 | Bob | 3 |
| 3 | Charlie | 2 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks