How to: Bind a Pivot Grid to an OLAP Data Source

  • 4 minutes to read

If you have a cube on the OLAP server (Microsoft Analysis Services), you can view its data using the Pivot Grid. This example demonstrates how to specify connection settings and create fields that represent measures and dimensions of the cube.

To bind the Pivot Grid control to an OLAP cube, follow the steps below.

  • Set ADOMD as data provider using the PivotGridControl.OLAPDataProvider property.
  • Specify connection settings using 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;

  • Create fields for measures and dimension in the bound OLAP cube. Use the PivotGridControl.RetrieveFields method overload that create fields, moves them to the specified area and makes them hidden. Another option is creating a new field and specifying its PivotGridFieldBase.OLAPExpression property.
  • Place the fields to the Pivot Grid Control areas as required and make them visible by setting the PivotGridFieldBase.Visible property.

Use the invoked Customization Form to arrange fields.


The complete sample project How to connect a Pivot Grid to an OLAP datasource is available at the DevExpress Examples repository on GitHub.

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

            // 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]"].OLAPDimensionCaption = "TEST";
            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 a query expression to obtain data and a caption to display it in the Customization form.
            PivotGridFieldBase fieldCountry = pivotGridControl1.Fields.Add("Country", PivotArea.RowArea);
            fieldCountry.OLAPExpression = "[Customer].[Country].[Country]";
            fieldCountry.OLAPDimensionCaption = "Location";

            PivotGridFieldBase fieldCity = pivotGridControl1.Fields.Add("City", PivotArea.RowArea);
            fieldCity.OLAPExpression = "[Customer].[City].[City]";
            fieldCity.OLAPDimensionCaption = "Location";

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

            PivotGridFieldBase fieldTop10 = pivotGridControl1.Fields.Add("Top10", PivotArea.ColumnArea);
            fieldTop10.OLAPExpression = "TOPCOUNT([Date].[Date].[Date].MEMBERS, 10, [Measures].[Internet Sales Amount])";
            fieldTop10.OLAPDimensionCaption = "Top";
            fieldTop10.Visible = false;;


            // Invoke the Customization Form.