ExpressionDataBinding Class
Defines a calculation based on a string expression.
Namespace: DevExpress.XtraPivotGrid
Assembly: DevExpress.XtraPivotGrid.v24.1.dll
NuGet Package: DevExpress.Win.PivotGrid
Declaration
Remarks
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:
- Create an
ExpressionDataBinding
instance and pass the expression in its constructor as a parameter. - Assign the created object to the PivotGridFieldBase.DataBinding property.
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));
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;
}
}
}