Skip to main content

ExpressionDataBinding Class

Defines a calculation based on a string expression.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v23.2.dll

NuGet Package: DevExpress.Win.PivotGrid

Declaration

public class ExpressionDataBinding :
    ExpressionBindingBase

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:

  1. Create an ExpressionDataBinding instance and pass the expression in its constructor as a parameter.
  2. 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));

Run Demo: Calculated Fields

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.

First Value Custom Function Example

View Example

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; 
        }      
    }
}

More Examples

View Example: Pivot Grid for WinForms - Display KPI Graphics

Inheritance

See Also