Monday, July 28, 2014

My first MDX query

Open up your SSMS (Sequel Server Management Studio) and make a connection to your “Adventure Works” OLAP database.
image
Click on the MDX query button: image .
This will gets us our workbench:
image
From the cube drop down we can select the cube we want to work with:
image for the time being we will leave it at Adventure Works.
In the query page enter:
SELECT
    [Measures].[Sales Amount] ON COLUMNS
FROM
    [Adventure Works]
This will get us:
image
Although it’s a nice sum it doesn’t really mean anything…. Let’s add the year 2010:
SELECT
    [Measures].[Sales Amount] ON COLUMNS
    ,
    [Date].[Calendar Year].&[2010] ON ROWS
FROM
    [Adventure Works]
This will get us:
image
Ok, that is one year, lets add several:
SELECT
    [Measures].[Sales Amount] ON COLUMNS
    ,
    {
      [Date].[Calendar Year].&[2010]
    , [Date].[Calendar Year].&[2011]
    , [Date].[Calendar Year].&[2013]
    , [Date].[Calendar Year].&[2014]    
    }   
    ON ROWS
FROM
    [Adventure Works]
This will get us:
image
Ok, but I don’t want to type out everything every time…. How about:
SELECT
    [Measures].[Sales Amount] ON COLUMNS
    ,
    {
      [Date].[Calendar Year].Children   
    }   
    ON ROWS
FROM
    [Adventure Works]
This will get us:
image
But I don’t want to see the years where there is no Sales Amount. So let’s filter out the years which are not empty (NULL):
SELECT
    [Measures].[Sales Amount] ON COLUMNS   
,NON EMPTY
   [Date].[Calendar Year].CHILDREN    ON ROWS
FROM
    [Adventure Works]
This will get us:
image
Have Fun And Till Next Time

No comments:

Post a Comment