Skip to main content

Custom Summary

  • 3 minutes to read

Total summaries and group summaries contain predefined aggregate functions. These functions allow you to calculate the following:

  • the number of data rows (Count)
  • the maximum and minimum values (Max and Min)
  • the sum and the average value (Sum and Average)

Handle the GridControl.CustomSummary event or use the GridControl.CustomSummaryCommand property to apply custom rules to calculate summaries. Custom summaries allow you to:

  • calculate summaries against records that meet specific criteria
  • involve multiple data fields in calculations
  • implement complex summary functions (for example, the standard deviation of a population), etc.

If the GridControl.View property is set to TreeListView, use the TreeListView.CustomSummary event or the TreeListView.CustomSummaryCommand property.

General Information

To calculate a summary manually:

  1. Create a summary item and set its SummaryItemBase.SummaryType property to SummaryItemType.Custom.
  2. Create a command that uses a custom algorithm to calculate summary values.
  3. Bind this command to the GridControl.CustomSummaryCommand property.

The GridControl calculates its summaries as follows:

The GridControl executes the CustomSummary command and sets the SummaryArgs.SummaryProcess property to Start. At this stage, you can initialize summary values (for example, reset internal counters).
The GridControl executes the CustomSummary command multiple times, once for each data row in a View or group. The SummaryArgs.SummaryProcess property is set to Calculate. At this stage, you can calculate summaries.
The GridControl executes the CustomSummary command and sets the SummaryArgs.SummaryProcess property to Finalize. At this stage, you can assign the calculated summary to the SummaryArgs.TotalValue property.

To skip the Calculation stage and calculate a custom summary at the Initialization or Finalization stage, set the SummaryArgs.TotalValueReady property to true at the Initialization stage. This skips the Calculation stage and starts the Finalization stage.


The following code sample calculates the total number of empty cells in the specified column:

DevExpress WPF | Grid Control - Custom Summaries

View Example: How to Use Custom Summaries

<dxg:GridControl ItemsSource="{Binding Items}"
                 CustomSummaryCommand="{Binding CustomSummaryCommand}">
        <dxg:GridColumn FieldName="Text" GroupIndex="0" />
        <dxg:GridColumn FieldName="Number" />
        <dxg:TableView AutoWidth="True"
                       ShowTotalSummary="True" />
        <dxg:GridSummaryItem DisplayFormat="Total empty cells count: {0}"
                             SummaryType="Custom" />
        <dxg:GridSummaryItem DisplayFormat="Group empty cells count: {0}"
                             SummaryType="Custom" />
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
// ...
public class MainViewModel : ViewModelBase {
// ...
    public void CustomSummary(RowSummaryArgs args) {
        if(args.SummaryItem.PropertyName != "Number")
        if(args.SummaryProcess == SummaryProcess.Start) {
            args.TotalValue = 0;
        if(args.SummaryProcess == SummaryProcess.Calculate) {
                args.TotalValue = (int)args.TotalValue + 1;
    bool IsEmptyCell(object fieldValue) {
        return !((int?)fieldValue).HasValue;