Aggregate Functions
The following aggregate functions are available:
| Function | Examples | Description |
|---|---|---|
| Count( expression[, scope[, query[, reportElement &cd;] ) | Count( Fax ) or Count( * ) | Counts all of the non null items of expression. Use a "*" for counting all items of the record set. |
| Sum( expression[, scope[, query[, reportElement &cd;] ) | Sum( LineTotal ) or Sum( Multiply( UnitPrice, Quantity ) ) | Sums all of the expression values. |
| First( expression[, scope[, query[, reportElement &cd;] ) | First( Fax ) | Returns the first expression value of all items of the record set. |
| Last( expression[, scope[, query[, reportElement &cd;] ) | Last( Fax ) | Returns the last expression value of all items of the record set. |
| Mean( expression[, scope[, query[, reportElement &cd;] ) | Mean( Quantity ) | Returns the average of all of the expression values. |
| Median( expression[, scope[, query[, reportElement &cd;] ) | Median( ProductName ) | Returns the median expression value. |
| Mode( expression[, scope[, query[, reportElement &cd;] ) | Mode( Marks ) | Returns the least most frequent expression value. |
| Max( expression[, scope[, query[, reportElement &cd;] ) | Max( Quantity ) | Returns the maximum expression value. |
| Min( expression[, scope[, query[, reportElement &cd;] ) | Min( Quantity ) | Returns the minimum expression value. |
| StDev( expression[, scope[, query[, reportElement &cd;] ) | StDev( Quantity ) | Returns the standard deviation of a numeric expression evaluated over a set. |
Aggregate functions can contain optional scope (scope) and query (query) values. The scope can be equal to the ID of the report or sub report within the report or it can also be specified as a page level scope (SEE BELOW). The Query value must be equal to the ID of any query within the report or sub report.
Page Level Aggregate Functions
Any aggregate function can be executed at the page level (calculations will be based on the number of records in the page). By default, an aggregate function uses the entire report to calculate the result of that function. To use the page as the scope for the function you must simply specify either “CurrentPage” or “PreviousPage” as the scope for that aggregate function. This is useful for instance if you wanted to keep a page total of a particular field for each page.
The four parameters that should be passed into the Page Level Aggregate Function are as follows in their respective order:
- Expression – Specifies the expression in which the aggregate function will be performed on. This value could be specified as the actual string of the field name or using the field index into the Query ID. This could also be another function.
- Scope – Specifies the scope to perform the function. Specify either “CurrentPage” or “PreviousPage”.
- QueryID – Specifies the ID of the Query from which the data is fetched. The QueryID can be of the query from the Report, Sub Report, Fixed Page or Document.
- ReportElementID – Specifies the actual report element id from the Detail section in which the above expression is will be calculated from. This ReportElementID is used when the Detail section of the Report has AutoSplit set to True. Specifying the ReportElementID assures that if a Detail section is split the value from the report element id will only get added to the function for the page in which the element will be displayed.
Current Page
Specifying “CurrentPage” scope gives the aggregate value of the current page. For example
- aggregateFunctionName ( Line Total, CurrentPage, ReportQuery, LineTotalRecordBox )
- aggregateFunctionName ( ReportQuery[4], CurrentPage, ReportQuery, LineTotalRecordBox)
Previous Page
Specifying “PreviousPage” scope gives the aggregate value of the previous page. For example
- aggregateFunctionName ( Line Total, PreviousPage, ReportQuery, LineTotalRecordBox )
- aggregateFunctionName ( ReportQuery[4], PreviousPage, ReportQuery, LineTotalRecordBox)
Important Notes
- Page Level Aggregate Functions are designed only to be used in the Header and Footer of the Report and SubReport. An exception will be thrown if they are used in a Detail section.
- Page Level Aggregate Functions cannot be used on Fixed Pages.