11. Report-Writer Expressions and Formats : Types of Data in Expressions : Aggregates : Unique Aggregates
 
Share this page                  
Unique Aggregates
You specify a unique aggregate by following the aggregate name with the letter "u," as in sumu, countu or avgu, respectively. The difference between a unique and a non-unique aggregate is that a unique aggregate performs an operation only when the value in the aggregate column changes, while a non-unique aggregate performs the operation for every value in the aggregate column. Therefore, a unique aggregate performs its calculation only on the break values in the specified column, up to the break containing the aggregate instruction.
For example, if you specify the aggregate, count(region), in the report footer for the sample report in the Population Example section of the appendix,
"Report-Writer Report Examples," the result would be 51 (remember District of Columbia), because there are 51 rows in the report. However, if you specify "countu(region)" instead, the result would be 9, because nine breaks occur on region.
The number of breaks is not necessarily the same as the actual unique values in the column. This result depends on the break in which the aggregate instruction is placed, and on whether the data in the aggregate column has been sorted or not. For instance, countu would produce a result of 3 on the following unsorted data in Column 1, even though the data contains only two unique values, because three breaks would occur:
Column 1

AAA
BBB
AAA