Custom Totals (Subtotals)
- 2 minutes to read
Automatic Totals and Custom Totals allow subtotals to be calculated against groups of data. These totals are calculated against a specific data field and they are displayed as an additional columns or rows for grouping field values which have nested field values. So, totals are not calculated for the values of the innermost column or row fields. If a specific field is neither a column field nor a row field, totals will not be calculated.
The following image shows a sample ExpressPivotGrid control which displays Automatic Totals:
In the image below the same ExpressPivotGrid is shown with Custom Totals enabled for the ‘Payment Type’ field. The Custom Totals replace the Automatic Totals for this field. Custom totals are not specified for the ‘Year’ field, so automatic totals are displayed for this field’s values.
The main differences between the Automatic and Custom Totals are listed in the following table.
Feature | Automatic Totals | Custom Totals |
---|---|---|
Association with fields | Automatic totals are not associated with fields. They are calculated for all the grouping values which have nested field values. | Custom totals are associated with column and row fields. They are calculated only for the grouping values of associated fields provided that these values have nested field values. Custom totals replace automatic totals for these field values. |
Collection of Total objects | The ExpressPivotGrid doesn’t provide a collection of automatic totals. | The custom total collection can be accessed via the corresponding field’s CustomTotals property. |
Number of Totals for individual field values | The number of automatic totals displayed for a specific field value matches the number of data fields. | The number of custom totals displayed for a specific field value is determined by the number of items in a field’s CustomTotals collection. |
Summary type | The type of the summary function used to calculate an automatic total is determined by the corresponding data field’s SummaryType property. | The type of the summary function used to calculate a custom total is specified by the custom total object (specifically by its SummaryType property). |
To display custom totals for a specific column/row field do the following:
set the field’s TotalsVisibility property to tvCustom;
add TcxPivotGridCustomTotal objects which represent custom totals to the field’s CustomTotals collection.
The TcxPivotGridCustomTotal class which implements a custom total provides properties to specify the total’s summary type and formatting settings.