# DML functions: Statistics

## Use Statistics Functions

When you perform Statistics Functions on a node set, you must write a Business Document Path to specify the node set or node on which you want to perform the operation. The Business Document Path can refer to either a single node or to a set of nodes.

### average

average Comment

Description

average sequentially reads the values in the specified node set of the input Business Document, and returns the average value of those nodes. Nodes without values, such as parent or segment nodes, cannot belong to the node set.

Syntax

average(node_set)

Return

Returns the same data class as the data class of the parameter. This can be an Integer or a Real number.

• Instances with a value null or absent are ignored.
• If no instance is found, the function returns the null value.
• If all instances have the value null or absent, the function returns null.

Parameters

node_set

Specify the node_set that contains the values that you want to average. You must specify a node with values (not, for example, a parent node).

The data class of the node set can be either of the following:

• I - Integer
• R - Real number

Example

In the following example, the average Function calculates the average for the values recorded in the Temperature node, and maps the returned value to the AverageTemp node in the output Business Document.

Expression WeatherStatistics Statistics (1-1) AverageTemp(1-1)

average(\TempRecord \Temperature) WeatherRecord TempRecord (1-N) Time (1-1) Temperature(1-1)

### c

average Comment

Description

count counts the number of nodes in the node set that you specify. The software also counts nodes without values, such as parent or segment nodes.

Syntax

count(node_set)

Return

Integer

Instances that do not contain values and instances that are not present, are ignored.

If no instance is found, the functions returns the value "0".

Parameters

node_set
Specify the node set that contains the nodes you want to count.

Example

In the following example, the count Function counts the number of occurrences of the TempRecord node, and maps the result to the NbrTempRecords node in the output Business Document.

Expression WeatherStatistics Statistics (1-1) NbrTempRecords(1-1)

count(\TempRecord) WeatherRecord TempRecord (1-N) Time (1-1) Temperature (1-1)

### max

max Comment

Description

max sequentially reads the values in the specified node set of the input Business Document, and returns the highest value that occurs in that node set. Nodes without values, such as parent or segment nodes, cannot belong to the node set.

Syntax

max(node_set)

Return

Returns the same data class as the data class of the parameter.

• Instances with a value null or absent are ignored.
• If no instance is found, the function returns the null value.
• If all instances have the value null or absent, the function returns null.

Parameter

node_set

Specify the node set that contains the values where you want the maximum value. You must specify a node with values (not, for example, a parent node).

The data class of the node set can be any of the following:

• B - Boolean
• I - Integer
• S - String
• D - Date
• R - Real number

Example

In the following example, the max Function reads the values recorded in the Temperature node, and maps the highest value found to the MaxTemp node in the output Business Document.

Expression WeatherStatistics Statistics (1-1) MaxTemp(1-1)

max(\TempRecord \Temperature) WeatherRecord TempRecord (1-N) Time (1-1) Temperature (1-1)

### min

min Comment

Description

min sequentially reads the values in the specified node set of the input Business Document, and returns the lowest value that occurs in that node set. Nodes without values, such as parent or segment nodes, cannot belong to the node set.

Syntax

min(node_set>)

Return

Returns the same data class as the data class of the parameter.

• Instances with a value null or absent are ignored.
• If no instance is found, the function returns the null value.
• If all instances have the value null or absent, the function returns null.

Parameters

node_set

Specify the node set that contains the values where you want the minimum value. You must specify a node with values (not, for example, a parent node).

The data class of the node set can be any of the following:

• B - Boolean
• I - Integer
• S - String
• D - Date
• R - Real number

Example

In the following example, the min Function reads the values recorded in the Temperature node, and maps the lowest (Real number) value found to the MinTemp node in the output Business Document.

Expression WeatherStatistics Statistics (1-1) MinTemp(1-1)

min(\TempRecord \Temperature) WeatherRecord TempRecord (1-N) Time (1-1) Temperature (1-1)

### sum

sum Comment

Description

sum sequentially reads the values in the specified node set of the input Business Document, and returns the total value of those nodes. Nodes without values, such as parent or segment nodes, cannot belong to the node set.

Syntax

sum(node_set)

Return

Returns the same data class as the data class of the parameter. This can be an Integer or a Real number.

• Instances with a value null or absent are ignored.
• If no instance is found, the function returns the null value.
• If all instances have the value null or absent, the function returns null.

Parameter

node_set

Specify the node_set that contains the values you want to total. You must specify a node with values (not, for example, a parent node).

The data class of the node set can be either of the following:

• I - Integer
• R - Real number

Example

In the following example, the sum Function calculates the total for the values recorded in the Price node of the input Business Document, and maps the returned value to the TotalPrice node in the output Business Document.

Expression ClientTransaction Statistics(1-1) TotalPrice(1-1)

sum(\Items\Price) ClientTransaction Items(1-N) CDs(1-1) Books(1-1) Price(1-1)

## Usage limits

You can use the Statistics Functions in the following DML expressions:

• Validation Rule