ComponentOne Olap for WinForms
OLAP for WinForms Task-Based Help / Specifying a Subtotal Function
In This Topic
    Specifying a Subtotal Function
    In This Topic

    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:

    1. Right-click a field in the Values area of the C1OlapPanel.
    2. Click Field Settings in the context menu. The Field Settings dialog box opens.
    3. Click the Subtotals tab.
    4. Select one of the following options:
      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.
    5. Click OK to close the Field Settings dialog box. Notice how the values in the summary table change.

    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";