Lesson 2 - Bind a Pivot Grid to an OLAP Cube

  • 3 min to read

A cube is a multidimensional structure defined by its measures and dimensions. You can think of a measure as a data field in PivotGridControl, while a dimension can be represented by a column field or a row field. This tutorial will help you learn how to bind a pivot grid to an existing OLAP (OnLine Analytical Processing) cube. In this example, we will use the Adventure Works cube.

To display data from an OLAP cube, do the following.

Specify a connection string to an OLAP cube.

  1. Run MS Visual Studio. Create a new WPF Application project and add PivotGridControl as you did in Lesson 1.
  2. Click the smart tag icon (SmartTag) displayed at the top-right of the pivot grid to invoke the Pivot Grid Control Tasks popup window.

    DXPivotGridGettingStartedL1_ItemSourceWizard

  3. In the invoked wizard, select OLAP Cube technology and click Next.

    DXPivotGridGettingStartedL2-I

  4. Select the ADOMD.NET as a data provider and click Next.

    GettingStarted_L2_step2

  5. In the next window, select the MSOLAP provider and specify the Server Name as https://demos.devexpress.com/Services/OLAP/msmdpump.dll. Then, click the Retrieve Schema button.

    GettinStarted_L2_RetrieveSchema

    Make sure that the following parameters are specified.

    Provider

    MSOLAP

    Identifies the data provider to be used. The "MSOLAP" string identifies the latest version of the OLE DB provider.

    Server Name

    https://demos.devexpress.com/Services/OLAP/msmdpump.dll

    Specifies either the name of a server that runs an instance of Microsoft SQL Server Analysis Services (SSAS), the path to a cube file or the path to a data pump.

    Catalog Name

    Adventure Works DW Standard Edition

    Specifies a data catalog that contains cubes.

    Cube Name

    Adventure Works

    Specifies the name of a cube that provides OLAP data.

    The image below demonstrates configured settings of the OLAP connection. Click Finish to close the wizard.

    GettinStarted_L2_CloseWizard

Create Fields

  1. Click the pivot grid's smart tag and use the Add Data Area Field menu item to add a new field to the Data Header Area. In a similar manner, add two fields both to the Column Header and Row Header areas.

    GetStart2_pivotgrid_AddFields

  2. To associate created fields with OLAP measures/dimensions, click the field's smart tag icon. In the invoked menu, click the FieldName property ellipsis button to see existing data source fields.

    GetStart2-PivotGrid-SpeecifyField

    Select the following measures and dimensions for created fields.

    • For the data field, select the [Measures].[Internet Sales Amount] measure.
    • For the column fields, select the [Date].[Fiscal].[Fiscal Year] and [Date].[Fiscal].[Fiscal Quarter] dimensions.
    • For the row fields, select the [Customer].[Country].[Country] and [Customer].[City].[City] dimensions.

    After this, your XAML should look like the following. If it does not, you can overwrite your code with:

    <Window
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid" 
            xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
            xmlns:local="clr-namespace:WpfPivotGridGettinStartedNewScreenshots" 
            x:Class="WpfPivotGridGettinStartedNewScreenshots.MainWindow"
            Title="DevExpress WPF Application" Height="350" Width="525">
        <Window.Resources>
            <dx:PivotOlapDataSource x:Key="PivotOlapDataSource" Cube="Adventure Works" 
                                    Catalog="Adventure Works DW Standard Edition" 
                                    ConnectionTimeout="60" LocaleIdentifier="1033" 
                                    Password="{x:Null}" Provider="MSOLAP" QueryTimeout="30" 
                                    Server="http://demos.devexpress.com/Services/OLAP/msmdpump.dll" 
                                    UserId="{x:Null}">
                <dx:DesignDataManager.DesignData>
                    <dx:DesignDataSettings RowCount="5"/>
                </dx:DesignDataManager.DesignData>
            </dx:PivotOlapDataSource>
        </Window.Resources>
        <Grid>
            <dxpg:PivotGridControl OlapDataProvider="Adomd" 
                       OlapConnectionString="{Binding ConnectionString, Source={StaticResource PivotOlapDataSource}}">
                <dxpg:PivotGridControl.Fields>
                    <dxpg:PivotGridField Area="DataArea" Caption="Internet Sales Amount" 
                                         FieldName="[Measures].[Internet Sales Amount]"/>
                    <dxpg:PivotGridField Area="ColumnArea" Caption="Fiscal Year" 
                                         FieldName="[Date].[Fiscal Year].[Fiscal Year]"/>
                    <dxpg:PivotGridField Area="ColumnArea" Caption="Fiscal Quarter of Year"
                                         FieldName="[Date].[Fiscal Quarter of Year].[Fiscal Quarter of Year]"/>
                    <dxpg:PivotGridField Area="RowArea" Caption="Country" 
                                         FieldName="[Customer].[Country].[Country]"/>
                    <dxpg:PivotGridField Area="RowArea" Caption="City" 
                                         FieldName="[Customer].[City].[City]" />
                </dxpg:PivotGridControl.Fields>
            </dxpg:PivotGridControl>
        </Grid>
    </Window>
    

Result

Run the project and see the result.

GettingStarted_L2_02

See Also