Table of Contents

Search

  1. Preface
  2. The Transformation Language
  3. Constants
  4. Operators
  5. Variables
  6. Dates
  7. Functions
  8. Creating Custom Functions
  9. Custom Function API Reference

Transformation Language Reference

Transformation Language Reference

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 nest only one other aggregate function within COUNT. You can apply a condition to filter rows before counting them.

Syntax

COUNT(
value
[,
filter_condition
] )
or
COUNT(
*
[,
filter_condition
] )
The following table describes the arguments for this command:
Argument
Required/
Optional
Description
value
Required
Any datatype 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 or no rows are selected, 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.
By default, the
PowerCenter Integration Service
treats null values as NULLs in aggregate functions. If you pass an entire port or group of null values, the function returns NULL. However, when you configure the
PowerCenter Integration Service
, you can choose how you want to handle null values in aggregate functions. You can treat null values as 0 in aggregate functions or as NULL.

Group By

COUNT groups values based on group by ports you define in the transformation, returning one result for each group. If there is no group by port 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

0 COMMENTS

We’d like to hear from you!