Question

I would like to combine two MDX queries from separate dimensions on columns. Example:

Number of Sales/Product Type vs. Gender and State:

      |  CA  |  OR  |  WA  |  Male  |  Female
------------------------------------------------
food  | 125  | 343  | 130  |  570   |   459
------------------------------------------------
drink | 123  | 465  | 135  |  678   |   343

State and Gender are their own respective dimensions, and I would like to do some aggregation (eg. sales count) across different product types (food, drink). Below is some idea of how this might work, although the queries can not be joined as they have different hierarchies. How might I go about tacking on male and female, for example, as columns in this result?

SELECT

  NON EMPTY 

  { [Store].[Store State].Members, [Gender].[Gender].Members } ON COLUMNS,

  { [Product].[Product Family].Members } ON ROWS

   FROM [Sales] 

WHERE { [Measures].[Sales Count] }

Example error:
MondrianEvaluationException: Expressions must have the same hierarchy

Is there a way to do this effectively in MDX,? If so, may I a specify specific aggregations for each colunm (eg. aggregate state data by total sales, gender data by profit).

Thank you for your help

Was it helpful?

Solution

In MDX, all axes must have the same dimensionality. The best approach would be to run two queries, and show them beside each other in the client tool.

However, you could do something similar to what @Vhteghem_Ph proposed:

SELECT

  NON EMPTY 

  [Store].[Store State].Members * { [Gender].[Gender].[(All Gender)] }
  +
  { [Store].[Store State].[(All Store State)] } * [Gender].[Gender].Members 
  ON COLUMNS,

  { [Product].[Product Family].Members } ON ROWS

   FROM [Sales] 

WHERE { [Measures].[Sales Count] }

Note that the + used here, which has two sets as parameters, is a short form of Union(set1, set2). And again, Union needs both sets to have the same dimensionality, in this case the first dimension of the set is the Store States hierarchy, and the second is the Gender hierarchy.

OTHER TIPS

I don't know if the following will work with mondrian:

SELECT 
  {[Measures].[Internet Sales Amount]} ON 0
 ,NON EMPTY 
    {
      (
        [Customer].[Gender].[Gender].MEMBERS
       ,[Customer].[Marital Status].[(All)]
      )
     ,(
        [Customer].[Gender].[(All)]
       ,[Customer].[Marital Status].[Marital Status].MEMBERS
      )
    } ON 1
FROM [Adventure Works];

Philip

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top