COUNT
- COUNT(array, value)[source]
Counts the number of occurrences of a specified value in an array.
COUNT evaluates the input array and returns the total number of times value appears. The value must be compatible with the data type of the array elements.
- Parameters:
array (
Operand) –The array to search for occurrences of value. Must be a valid array type or object array.
Supported types:
BOOLEAN_ARRAY
INTEGER_ARRAY
DECIMAL_ARRAY
STRING_ARRAY
DATE_ARRAY
TIME_ARRAY
DATETIME_ARRAY
OBJECT_ARRAY
value (
Operand|int|float|str|bool) –The value to count in the array. Must have the same data type as the array elements.
Supported types:
BOOLEAN
INTEGER
DECIMAL
STRING
DATE
TIME
DATETIME
OBJECT
- Return type:
- Returns:
A formula object evaluating to an INTEGER representing the count of value in array.
Supported types:
INTEGER
- Raises:
ValueError – If array is not an array type
ValueError – If value does not match the array element type
Examples
Counting numeric occurrences:
COUNT([1, 2, 1, 3, 1], 1) # Returns 3 # Explanation: The value 1 occurs three times
Counting string occurrences:
COUNT(["A", "B", "A", "C"], "A") # Returns 2 # Explanation: "A" appears twice in the array
Counting boolean occurrences:
COUNT([True, False, True, True], True) # Returns 3