Search code examples
ssasmdx

MDX - 3rd + dimension example needed


I am trying to learn MDX. I am an experienced SQL Developer.

I am trying to find an example of an MDX query that has more than two dimensions. Every single webpage that talks about MDX provides simple two dimensional examples link this:

select 
{[Measures].[Sales Amount]} on columns,
Customer.fullname.members on rows
from [Adventure Works DW2012]

I am looking for examples that use the following aliases: PAGES (third dimension?), section (forth dimension?) and Chapter (fifth dimension?). I have tried this but I do not think it is correct:

select 
{[Measures].[Sales Amount]} on columns,
Customer.fullname.members on rows,
customer.Location.[Customer Geography] as pages
from [Adventure Works DW2012]

I am trying to get this output using an MDX query (this is from AdventureWorks DW2012):

enter image description here


Solution

  • That's not a 3-dimensional resultset in your screenshot, unless there's something cropped from it.

    Something like

    SELECT [Geography].[Country].Members ON 0,
    [Customer].[CustomerName].Members ON 1
    FROM [whatever the cube is called]
    WHERE [Measures].[Sales Amount]
    

    (dimension/hierarchy/level names may not be exactly right) would give a resultset like the one in your message.

    The beyond 2nd-dimension dimensions and dimension names are not used in any client tool that I know. (Others may know different). They seem to be there in MDX so that MDX can hand >2-dimensional resultsets to clients that can handle them (e.g. an MDX subquery handing its results to the main query).

    An often-used trick in MDX is to get the members of two dimensions onto one axis by cross-joining:

    SELECT {[Date].[Calendar Date].[Calendar Year].Members * [Geography].[Country].Members} ON 0, [something else] ON 1 FROM [Cube]