Back to Devexpress

Bind Pivot Grid Fields to Calculated Expressions

windowsforms-404009-controls-and-libraries-pivot-grid-binding-to-data-olap-mode-bind-pivot-grid-fields-to-calculated-expressions.md

latest2.8 KB
Original Source

Bind Pivot Grid Fields to Calculated Expressions

  • Aug 05, 2022
  • 2 minutes to read

This topic describes how to use the Binding API to create calculated fields in OLAP mode.

Calculated fields display the result of calculated expressions. Each calculated field has a binding expression that can be a formula or an aggregate function. The expression allows you to not only obtain values from a field in the data source, but specify exactly how to calculate the data (for example, aggregate it).

Create a Calculated Field in Visual Studio Designer

Follow the steps below to create a calculated field in the Pivot Grid:

  1. Add a new data field in any of the following ways:

  2. Set the field’s PivotGridFieldBase.DataBinding property to OLAP Expression.

  3. Specify the MDX expression.

Note

You cannot use the Expression Editor dialog in OLAP mode.

Create a Calculated Field in Code

OLAP mode supports OLAPExpressionBinding.

Follow the steps below to create a calculated field in OLAP mode:

  1. Create an OLAPExpressionBinding instance and pass the expression in its constructor as a parameter. You can also use the object’s OLAPExpressionBindingBase.Expression property to specify the expression.
  2. Assign the created object to the PivotGridFieldBase.DataBinding property.

The following code snippet shows how to bind measureField to the MDX expression:

cs
PivotGridField measureField = new PivotGridField() { Caption = "Cleared Amount", 
   Area = PivotArea.DataArea };
measureField.DataBinding = new OLAPExpressionBinding("[Measures].[Internet Sales Amount] * 0.87");
measureField.Name = "fieldInternetSalesAmount";
pivotGridControl1.Fields.Add(measureField);
vb
Dim measureField As PivotGridField = New PivotGridField() With {.Caption = "Cleared Amount", .Area = PivotArea.DataArea}
measureField.DataBinding = New OLAPExpressionBinding("[Measures].[Internet Sales Amount] * 0.87")
measureField.Name = "fieldInternetSalesAmount"
pivotGridControl1.Fields.Add(measureField)

View Example