Sum

Description

Calculates the sum of the values in the specified column.

Syntax

Sum ( column { FOR range { DISTINCT { expres1 {, expres2  {, ... } } } } } )

Argument

Description

column

The column for which you want the sum of the data values. Column can be the column name or the column number preceded by a pound sign (#). Column can also be an expression that includes a reference to the column. The datatype of column must be numeric.

FOR range (optional)

The data to be included in the sum. For most presentation styles, values for range are:

  • ALL – (Default) The sum of all values in column.

  • GROUP n – The sum of values in column in the specified group. Specify the keyword GROUP followed by the group number: for example, GROUP 1.

  • PAGE – The sum of the values in column on a page.

For Crosstabs, specify CROSSTAB for range:

  • CROSSTAB – (Crosstabs only) The sum of all values in column in the crosstab.

For Graph objects, specify the following:

  • GRAPH – (Graphs only) The sum of values in column in the range specified for the Rows option of the graph.

DISTINCT (optional)

Causes Sum to consider only the distinct values in column when determining the sum. For a value of column, the first row found with the value is used and other rows that have the same value are ignored.

expresn (optional)

One or more expressions that you want to evaluate to determine distinct rows. Expresn can be the name of a column, a function, or an expression.

Returns

The appropriate numeric datatype. Returns the sum of the data values in column.

Usage

If you specify range, Sum returns the sum of the values in column within range. If you specify DISTINCT, Sum returns the sum of the distinct values in column, or if you specify expresn, the sum of the values of column where the value of expresn is distinct.

For graphs, you do not select the range when you call the function. The range has already been determined by the Rows setting on the Data property page (the Range property), and the aggregation function uses that range. Settings for Rows include the following:

Null values are ignored and are not included in the calculation.

NoteNot in validation rules or filter expressions You cannot use this or other aggregate functions in validation rules or filter expressions.

Using an aggregate function cancels the effect of setting Retrieve Rows As Needed in the painter. To do the aggregation, a DataWindow object always retrieves all rows.

Examples

Example 1

This expression returns the sum of the values in group 1 in the column named salary:

Sum(salary for group 1)

Example 2

This expression returns the sum of the values in column 4 on the page:

Sum(#4 for page)

Example 3

Assuming a DataWindow object displays the order number, amount, and line items for each order, this computed field returns the sum of the order amount for the distinct order numbers:

Sum(order_amt for all DISTINCT order_nbr)

See also