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

Custom Summaries

  • 3 minutes to read

Custom summaries allow you to manually calculate summaries using custom algorithms. This can be useful in the following instances:

  • calculating a custom summary function;
  • using multiple data fields in a summary calculation;
  • calculating a summary for individual records (for instance, for the records which match specific criteria).

To enable a custom summary calculations, set the data field’s PivotGridField.SummaryType property to FieldSummaryType.Custom. Handle the PivotGridControl.CustomSummary event to implement a custom summary calculation algorithm. This event is fired for each summary cell that corresponds to this data field.

Note

When handling the PivotGridControl.CustomSummary event, use the PivotCustomSummaryEventArgs.CreateDrillDownDataSource method to obtain a subset of records in a datasource, which corresponds to the currently processed summary cell.

Note

Custom summaries calculated using the PivotGridControl.CustomSummary event are not supported in server mode.

Example: How to Calculate Custom Summaries

This example demonstrates how to use Custom Summaries to count distinct values (the number of orders with equal product quantities) and display the result in the pivot grid.

This example handles the CustomSummary event that occurs when the control calculates a summary for a field whose SummaryType is PivotSummaryType.Custom. The event handler calls the e.CreateDrillDownDataSource method to retrieve the underlying data rows for the current cell, counts distinct values and returns the result to the e.CustomValue property.

Note

The complete sample project How to Create a Custom Summary Type to Display the Distinct Value Count is available in the DevExpress Examples repository.

<dx:ThemedWindow x:Class="DXPivotGrid_CustomSummary.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800" 
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:DXPivotGrid_CustomSummary" 
    xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid">
    <Grid>

        <dxpg:PivotGridControl CustomSummary="pivotGridControl1_CustomSummary" Loaded="PivotGridControl1_Loaded" Name="pivotGridControl1">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldCategoryName" FieldName="CategoryName" Area="RowArea" AreaIndex="0" Caption="Category Name" />
                <dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName" Area="RowArea" AreaIndex="1" Caption="Product Name" />
                <dxpg:PivotGridField Name="fieldOrderDate" FieldName="OrderDate" Area="ColumnArea" AreaIndex="0" Caption="OrderDate" GroupInterval="DateYear" />
                <dxpg:PivotGridField Name="fieldQuantity" FieldName="Quantity" Area="DataArea" AreaIndex="0" Caption="Quantity" />
                <dxpg:PivotGridField Name="fieldQuantityDistinctCount" FieldName="Quantity" Area="DataArea" AreaIndex="1" Caption="Count Distinct" SummaryType="Custom" />
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>

    </Grid>
</dx:ThemedWindow>