windowsforms-9391-controls-and-libraries-pivot-grid-data-shaping-summarization-summaries-custom-summaries.md
This topic describes how to create custom summaries.
Pivot Grid allows you to calculate common summary functions for data fields. You can create custom summaries to execute complex calculations.
Custom summaries can do the following:
Do the following to create a custom summary for a data field:
ExpressionDataBinding object to the field’s DataBinding property.Refer to the following article for information on how to create calculated expressions: Calculated Fields.
Tip
If a custom summary calculation requires data from multiple data sources, bind the Pivot Grid to a FederationDataSource that combines data from two or more tables into one data set. The custom summary expression can then use fields defined in the FederationDataSource.
The following example specifies a custom summary for the First Product Sold field. The custom summary’s expression (FirstValue([ProductName])) uses a custom aggregate function (FirstValue) to return the first product sold by a sales person in each product category.
using DevExpress.XtraPivotGrid;
using System.Windows.Forms;
namespace WinPivot_CustomFunctions {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
// ...
pivotGridControl1.OptionsData.DataProcessingEngine = PivotDataProcessingEngine.Optimized;
PivotGridField pivotGridField1 = new PivotGridField() {
Area = PivotArea.DataArea,
AreaIndex = 0,
Caption = "First Product Sold",
FieldName = "FirstProductSold"
};
pivotGridControl1.Fields.Add(pivotGridField1);
pivotGridField1.DataBinding = new ExpressionDataBinding() {
Expression = "FirstValue([ProductName])" };
pivotGridField1.Options.ShowExpressionEditorMenu = true;
pivotGridField1.Options.ShowGrandTotal = false;
}
}
}
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid
Namespace WinPivot_CustomFunctions
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
' ...
pivotGridControl1.OptionsData.DataProcessingEngine = PivotDataProcessingEngine.Optimized
Dim pivotGridField1 As New PivotGridField() With {
.Area = PivotArea.DataArea,
.AreaIndex = 0,
.Caption = "First Product Sold",
.FieldName = "FirstProductSold"
}
pivotGridControl1.Fields.Add(pivotGridField1)
pivotGridField1.DataBinding = New ExpressionDataBinding() With {.Expression = "FirstValue([ProductName])"}
pivotGridField1.Options.ShowExpressionEditorMenu = True
pivotGridField1.Options.ShowGrandTotal = False
End Sub
End Class
End Namespace
Use the PivotGridControl.CustomSummary event to create custom summaries in Legacy or LegacyOptimized mode.
Refer to the following articles for more information about custom functions:
See Also
Calculate and Display Custom Summaries When Pivot Grid Operates in Different Data Processing Modes