Skip to main content
A newer version of this page is available. .

How to: Add Custom Totals

In the following example, four custom totals are added for a ‘Category Name’ row field. They will calculate the total Average, Sum, Min and Max values against the currently displayed data field.

The result is shown below.

PivotGridField_CustomTotals_Ex

using DevExpress.Data.PivotGrid;
using DevExpress.XtraPivotGrid;

// Get a reference to the CategoryName field.
PivotGridField field = pivotGridControl1.Fields["CategoryName"];
pivotGridControl1.BeginUpdate();
try {
   // Clear the custom total collection.
   field.CustomTotals.Clear();
   // Add four items to the custom total collection to calculate the Average, 
   // Sum, Max and Min summaries.
   field.CustomTotals.Add(PivotSummaryType.Average);
   field.CustomTotals.Add(PivotSummaryType.Sum);
   field.CustomTotals.Add(PivotSummaryType.Max);
   field.CustomTotals.Add(PivotSummaryType.Min);
   // Make the custom totals visible for this field.
   field.TotalsVisibility = PivotTotalsVisibility.CustomTotals; 
}
finally {
   pivotGridControl1.EndUpdate();
}