When creating custom views of data, you may want to perform a different aggregate function other than "Sum" on your column or row. For example, you may want to find the average or maximum values in your data. This can easily be done through the Field Settings dialog box or in code.
To specify the function performed on data at run time:
Sum | Gets the sum of a group. |
Count | Gets the number of values in a group. |
Average | Gets the average of a group. |
Maximum | Gets the maximum value in a group. |
Minimum | Gets the minimum value in a group. |
First | Gets the first value in a group. |
Last | Gets the last value in a group. |
Variance | Gets the sample variance of a group. |
Standard Deviation | Gets the sample standard deviation of a group. |
Variance Population | Gets the population variance of a group. |
Standard Deviation Population | Gets the population standard deviation of a group. |
To specify the function performed on data in code:
Use the Subtotal property of the field to specify the function. In this example code, first the view is created, and then the average unit price is calculated for each product.
// build view
var olap = this.c1OlapPage1.OlapEngine;
olap.ValueFields.Add("UnitPrice");
olap.RowFields.Add("OrderDate", "ProductName");
// format unit price and calculate average
var field = olap.Fields["UnitPrice"];
field.Subtotal = Subtotal.Average;
field.Format = "c";