Function Reference > Functions > COUNT
  

COUNT

Returns the number of rows that have non-null values in a group. Optionally, you can include the asterisk (*) argument to count all input values in a transformation. You can apply a condition to filter rows before counting them.
You can nest only one other aggregate function within COUNT. You cannot nest aggregate functions in an elastic mapping.
Use only in mapping tasks.

Syntax

COUNT( value [, filter_condition] )
or
COUNT( * [, filter_condition] )
Argument
Required/
Optional
Description
value
Required
Any data type except binary. Passes the values you want to count. You can enter any valid transformation expression.
*
Optional
Use to count all rows in a transformation.
filter_condition
Optional
Limits the rows in the search. The filter condition must be a numeric value or evaluate to TRUE, FALSE, or NULL. You can enter any valid transformation expression.

Return Value

Integer.
0 if all values passed to this function are NULL (unless you include the asterisk argument).

Nulls

If all values are NULL, the function returns 0.
If you apply the asterisk argument, this function counts all rows, regardless if a column in a row contains a null value.
If you apply the value argument, this function ignores columns with null values.

Group By

COUNT groups values based on group by fields you define in the transformation, returning one result for each group. If there is no group by field COUNT treats all rows as one group, returning one value.

Examples

The following expression counts the items with less than 5 quantity in stock, excluding null values:
COUNT( ITEM_NAME, IN_STOCK < 5 )
ITEM_NAME
IN_STOCK
Flashlight
10
NULL
2
Compass
NULL
Regulator System
5
Safety Knife
8
Halogen Flashlight
1
RETURN VALUE: 1
In this example, the function counted the Halogen flashlight but not the NULL item. The function counts all rows in a transformation, including null values, as illustrated in the following example:
COUNT( *, QTY < 5 )
ITEM_NAME
QTY
Flashlight
10
NULL
2
Compass
NULL
Regulator System
5
Safety Knife
8
Halogen Flashlight
1
RETURN VALUE: 2
In this example, the function counts the NULL item and the Halogen Flashlight. If you include the asterisk argument, but do not use a filter, the function counts all rows that pass into the transformation. For example:
COUNT( * )
ITEM_NAME
QTY
Flashlight
10
NULL
2
Compass
NULL
Regulator System
5
Safety Knife
8
Halogen Flashlight
1
RETURN VALUE: 6