TOTAL command
Concept Information
Calculates the total value of one or more fields in an Analytics table.
Syntax
TOTAL {<FIELDS> numeric_field <...n>|<FIELDS> ALL <EXCLUDE numeric_field <...n>>} <IF test> <WHILE test> <FIRST range|NEXT range>
Parameters
Name | Description |
---|---|
FIELDS numeric_field <...n> | FIELDS ALL |
The numeric field or fields to total. Specify ALL to total each of the numeric fields in the table. |
EXCLUDE numeric_field optional |
Only valid when totaling using FIELDS ALL. The field or fields to exclude from the command. EXCLUDE allows you to fine-tune FIELDS ALL, by excluding the specified fields. EXCLUDE must immediately follow FIELDS ALL. For example: FIELDS ALL EXCLUDE field_1 field_2 |
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:
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
Note
If you total more than one field in a table, the system-generated output variable contains the total for the first listed field only.
Name | Contains |
---|---|
TOTALn |
The total value calculated by the command. The value of n is 1 unless the TOTAL command is inside a GROUP command, in which case the value of n corresponds to the line number of the TOTAL command in the GROUP command. For more information, see GROUP command. |
Examples
Totaling the first 25 records
You calculate the total amount of the MKTVAL field for the first 25 records in the table:
TOTAL FIELDS MKTVAL FIRST 25
Remarks
When to use TOTAL
Use TOTAL to verify the completeness and accuracy of the source data and to produce control totals. The command calculates the arithmetic sum of the specified fields or expressions.