windowsforms-devexpress-dot-xtrapivotgrid-e5d49d04.md
Defines a calculation based on a string expression.
Namespace : DevExpress.XtraPivotGrid
Assembly : DevExpress.XtraPivotGrid.v25.2.dll
NuGet Package : DevExpress.Win.PivotGrid
public class ExpressionDataBinding :
ExpressionBindingBase
Public Class ExpressionDataBinding
Inherits ExpressionBindingBase
Pivot Grid allows you to create calculated fields. They do not obtain their values from fields in the data source. Instead, you specify a binding expression. The expression can be a formula or an aggregate function.
Note
Use OLAPExpressionBinding for OLAP mode.
Follow the steps below to create a calculated field in Optimized and Server modes:
ExpressionDataBinding instance and pass the expression in its constructor as a parameter.The following code snippet shows how to bind fieldSalesPerson to the expression:
PivotGridFieldBase fieldSalesPerson = pivotGridControl1.Fields.Add();
fieldSalesPerson.DataBinding = new ExpressionDataBinding(string.Format(
"Concat([{0}], ' ', [{1}], ' (', [{2}], ')')", fieldFirstName.Name, fieldLastName.Name, fieldEmployeeID.Name));
Dim fieldSalesPerson As PivotGridFieldBase = pivotGridControl1.Fields.Add()
fieldSalesPerson.DataBinding = New ExpressionDataBinding(String.Format(
"Concat([{0}], ' ', [{1}], ' (', [{2}], ')')", fieldFirstName.Name, fieldLastName.Name, fieldEmployeeID.Name))
Refer to the following article for more information: Calculated Fields.
You can create functions with custom logic to build an expression that executes complex calculations for a Pivot Grid’s field.
Refer to the following articles for more information about custom functions:
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
View Example: Pivot Grid for WinForms - Display KPI Graphics
Object DataBindingBase ExpressionBindingBase ExpressionDataBinding
See Also
Bind Pivot Grid Fields to Calculated Expressions
Pivot Grid Data Processing Modes
Bind Pivot Grid Fields to Data Columns
Bind Pivot Grid Fields to Calculated Expressions