Creating Window Calculations
- 2 minutes to read
Follow the steps below to create a PivotGrid field that uses a window function to calculate its data.
- Switch to the Optimized Mode.
- Create a PivotGridField instance and specify the field’s caption, location, name, and format.
Create a data binding class instance.
You can choose a predefined binding class instance:
You can also use the WindowExpressionBinding type to specify a custom string as an expression that uses window functions:
WinForms WPF ASP.NET Description DevExpress.XtraPivotGrid.WindowExpressionBinding DevExpress.Xpf.PivotGrid.WindowExpressionBinding DevExpress.Web.ASPxPivotGrid.WindowExpressionBinding A custom calculation with window functions. Specify the partitioning criteria to define a window and the calculation direction for certain calculation types.
- Assign the data binding instance to the PivotGridField.DataBinding property.
- Add the field to the PivotGridControl.Fields collection.
Note
The complete sample project is available in the DevExpress Demo Center: Code Examples - Optimized Mode - Field Calculation Bindings module in the XtraPivotGrid MainDemo.
pivotGridControl.OptionsData.DataProcessingEngine = PivotDataProcessingEngine.Optimized;
PivotGridField fieldProductAmount = new PivotGridField() {
Area = PivotArea.DataArea,
Caption = "Product Sales",
Name = "fProductAmount"
};
PivotGridField fieldProductAmountRunningTotal = new PivotGridField {
Area = PivotArea.DataArea,
Caption = "Running Total",
Name = "fRunningTotal"
};
DataSourceColumnBinding productAmountBinding = new DataSourceColumnBinding("ProductAmount");
//Bind a field to a column in the data source.
fieldProductAmount.DataBinding = productAmountBinding;
//Calculate a running summary of the column.
fieldProductAmountRunningTotal.DataBinding = new RunningTotalBinding() {
Source = productAmountBinding,
PartitioningCriteria = CalculationPartitioningCriteria.ColumnValue,
SummaryType = PivotSummaryType.Sum
};
pivotGridControl.Fields.AddRange(new PivotGridField[] { fieldProductAmount, fieldProductAmountRunningTotal });
See Also