Skip to main content

PivotGridFieldBase.OLAPExpression Property

Gets or sets an expression used to evaluate values for the current unbound field in OLAP.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.PivotGrid.v22.2.Core.dll

NuGet Packages: DevExpress.PivotGrid.Core, DevExpress.Win.Dashboard.Design


public string OLAPExpression { get; set; }

Property Value

Type Default Description
String null

A string that represents an expression used to evaluate values for the current field in OLAP.


This example demonstrates how to specify connection settings and create fields that are bound to measures and dimensions of the cube on the OLAP server.

Follow the steps below to bind the Pivot Grid control to an OLAP cube in code.

  1. Set the PivotGridControl.OLAPDataProvider property to ADOMD.
  2. Specify connection settings in the PivotGridControl.OLAPConnectionString property. The following connection string is used in this example:

    Provider=MSOLAP;Data Source=;Initial catalog=Adventure Works DW Standard Edition;Cube name=Adventure Works;Query Timeout=100;

    Note that a valid connection string should include the following parameters: Provider, Data Source, Initial Catalog, Cube Name.

You can create Pivot Grid fields and bind them to measures and dimensions in the OLAP cube in the following ways:

Specify the value of the PivotGridFieldBase.Name property for each field when you create Pivot Grid fields. You can use this value to determine fields in a stored layout.

Use the following properties to specify field settings:

Gets or sets the area in which the field is displayed.
Gets or sets the field’s index from among the other fields displayed within the same area.
Gets or sets whether the field is visible.

Use the invoked Customization Form to arrange fields.

View Example: How to Connect a Pivot Grid to an OLAP Data Source

using DevExpress.XtraPivotGrid;
using DevExpress.XtraPivotGrid.Customization;

namespace WinOlapRetrieveFieldsExample {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            // Specify the OLAP connection settings.
            pivotGridControl1.OLAPDataProvider = OLAPDataProvider.Adomd;
            pivotGridControl1.OLAPConnectionString =
                Data Source=; 
                Initial catalog=Adventure Works DW Standard Edition;
                Cube name=Adventure Works;
                Query Timeout=100;";

            // Set the Customization Forms style.
            pivotGridControl1.OptionsCustomization.CustomizationFormStyle = CustomizationFormStyle.Excel2007;
            // Invoke the Customization Form.

        private void btnRetrieveFields_Click(object sender, System.EventArgs e) {
            // Retrieve fields.
            pivotGridControl1.RetrieveFields(PivotArea.ColumnArea, false);
            foreach (PivotGridField field in pivotGridControl1.Fields){
                field.Name = "field" + (field.DataBinding as DataSourceColumnBinding).ColumnName;

            // Add fields from the Field List to the specified area to create a report.
            pivotGridControl1.Fields["[Customer].[Country].[Country]"].Area = PivotArea.RowArea;
            pivotGridControl1.Fields["[Customer].[Country].[Country]"].Visible = true;
            pivotGridControl1.Fields["[Customer].[City].[City]"].Area = PivotArea.RowArea;
            pivotGridControl1.Fields["[Customer].[City].[City]"].Visible = true;
            pivotGridControl1.Fields["[Date].[Fiscal].[Fiscal Year]"].Area = PivotArea.ColumnArea;
            pivotGridControl1.Fields["[Date].[Fiscal].[Fiscal Year]"].Visible = true;
            pivotGridControl1.Fields["[Measures].[Internet Sales Amount]"].Visible = true;

            // Resize columns automatically.

            // Invoke the Customization Form.

        private void btnCreateFields_Click(object sender, System.EventArgs e) {

            // Create a field, specify its settings and bind the field to a measure or dimension.
            PivotGridField fieldCountry = pivotGridControl1.Fields.Add("Country", PivotArea.RowArea);
            fieldCountry.DataBinding = new DataSourceColumnBinding("[Customer].[Country].[Country]");
            fieldCountry.Name = "fieldCountry";

            PivotGridField fieldCity = pivotGridControl1.Fields.Add("City", PivotArea.RowArea);
            fieldCity.DataBinding = new DataSourceColumnBinding("[Customer].[City].[City]");
            fieldCity.Name = "fieldCity";

            PivotGridField measureField = new PivotGridField() { Caption = "Cleared Amount", 
               Area = PivotArea.DataArea };
            measureField.DataBinding = new OLAPExpressionBinding("[Measures].[Internet Sales Amount] * 0.87");
            measureField.Name = "fieldInternetSalesAmount";

            PivotGridFieldBase fieldTop10 = pivotGridControl1.Fields.Add("Top10", PivotArea.ColumnArea);
            fieldTop10.DataBinding = new OLAPExpressionBinding("TOPCOUNT([Date].[Date].[Date].MEMBERS, 10, " +
                "[Measures].[Internet Sales Amount])");
            fieldTop10.Visible = false;;
            fieldTop10.Name = "fieldTopcount";


            // Invoke the Customization Form.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the OLAPExpression property.


The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also