COUNT command

Concept Information

Counting records

Counts the total number of records in the current view, or only those records that meet the specified condition.

Syntax

COUNT <IF test> <WHILE test> <FIRST range|NEXT range>

Parameters

Name Description
IF test

optional

A conditional expression that must be true in order to process each record. The command is executed on only those records that satisfy the condition.

Note

The IF parameter is evaluated against only the records remaining in a table after any scope parameters have been applied (WHILE, FIRST, NEXT).

WHILE test

optional

A conditional expression that must be true in order to process each record. The command is executed until the condition evaluates as false, or the end of the table is reached.

Note

If you use WHILE in conjunction with FIRST or NEXT, record processing stops as soon as one limit is reached.

FIRST range | NEXT range

optional

The number of records to process:

  • FIRST start processing from the first record until the specified number of records is reached
  • NEXT start processing from the currently selected record until the specified number of records is reached

Use range to specify the number of records to process.

If you omit FIRST and NEXT, all records are processed by default.

Analytics output variables

Name Contains
COUNTn

The record count calculated by the command.

  • If the variable name is COUNT1, it is storing the record count for the most recent command executed.
  • If the variable name is COUNTn, where n is greater than 1, the variable is storing the record count for a command executed within a GROUP command.

    The value of n is assigned based on the line number of the command in the GROUP. For example, if the command is one line below the GROUP command it is assigned the value COUNT2. If the command is four lines below the GROUP command, it is assigned the value COUNT5.

Examples

Storing COUNT1

The result of the COUNT command is stored in the COUNT1 output variable. You can retrieve and store this value in a user-defined variable.

The COUNT command overwrites the COUNT1 variable each time it is executed, so the value needs to be stored in a user-defined variable before the command is executed for the second time after the filter is applied to the table:

OPEN CustomerAddress
COUNT
TotalRec = COUNT1
SET FILTER TO ModifiedDate > '20100101'
COUNT
TotalFilteredRec = COUNT1

Remarks

When to use COUNT

Use the COUNT command to count the number of records in an Analytics table, or to count the number of records that meet a particular test condition. If no test is specified, the total number of records in the Analytics table is displayed.

How filters affect COUNT

If a filter has been applied to a view, the command counts the number of records remaining in the view after the filtering condition has been applied.