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"])Result | |
|---|---|
| 1 | 3 |
Example 2: Count fields in the first row of Sales
Record.FieldCount(Sales{0})Result | |
|---|---|
| 1 | 8 |
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
WithCountA | B | C | D | FieldCount | |
|---|---|---|---|---|---|
| 1 | 1 | 2 | 3 | null | 3 |
| 2 | 1 | 2 | 3 | 4 | 4 |
| 3 | 1 | 2 | null | null | 2 |