Online Example: How to use aggregate functions in Calculated Field expressions
This tutorial describes the steps required to create a report with an aggregate function. In this example, products that are not discontinued and have a total unit value greater than $500 will be displayed.
Do the following to calculate an aggregate function:
To create a table report in this tutorial, start with a report that is bound to the "Categories" and "Products" tables of the sample Northwind database (the nwind.mdb file is included with the XtraReports installation).
See Bind a Report to Multiple Data Tables to learn more about binding a report to multiple data tables.
This tutorial starts with the following report layout:
Click the ellipsis button in the Expression section of Properties window. The Expression Editor dialog will appear.
In this dialog, double click the [CategoriesProducts] field and choose Functions | Aggregate. Then, double click the Count() function, and insert the following text in the empty square brackets.
"Not[Discontinued]And[UnitTotal] >= 500".
To construct a valid aggregate expression, use the following format, which consists of four parts.
You can refer to the currently processed group using the Parent Relationship Traversal Operator ('^'). This allows you to calculate aggregates within groups using expressions like the following: [[^.CategoryID] == [CategoryID]].Sum([UnitPrice]).
For more information, see Expression Constants, Operators, and Functions.
Next, add three XRLabel objects to the Detail Band and customize their content, as shown in the image below.