Search code examples
mdxolapdata-warehousemondrian

Select one hierarchy on a dimension with multiple hierarchies


I do have a cube V that has a measure Q and some dimensions D, F. In the dimension D I wanna have 2 hierarchies that share some common members, here they are (the 2 hierarchies are A and T and the common members are M and I):

-D
   -A
       +A
       +M
       +I
   -T
       +T
       +M
       +I

I'm trying with no success to create a MDX query to access either A and T:

select {[Measures].[Q]} ON COLUMNS,
  {([F], [D].[A]} ON ROWS
from [V]

but I do get an error from JPivot using Mondrian saying that

Mondrian Error:MDX object '[D].[A]' not found in cube 'V'. So I cannot access neither.

This is my first attempt at MDX, so I recognize I might have missed something from the cube construction or the language understanding.


Solution

  • Usually that error is returned when the member you're referencing doesn't exist in your dimension. The right syntax to refer to a particular Hierarchy (aside from the default) is [Dimension.Hierarchy], so try this

    select {[Measures].[Q]} ON COLUMNS,
      {([F], [D.A])} ON ROWS
    from [V]
    

    Assuming your A hierarchy has an All member then it should work.

    EDIT: I thought you couldn't do this in Mondrian but after trying it, it turns out you can: Try crossjoining the two hierarchies' members:

    SELECT NON EMPTY {[Measures].[Q]} ON COLUMNS,
      NON EMPTY CROSSJOIN([D.A].[Year].Members, [D.T].[Type].Members) ON ROWS
    FROM [V]
    

    The NON EMPTY functions will prevent combinations of the A and T hierarchies that do not have values from showing up in your output. Mind you, this will not really allow you to drill from Year down to Type, rather they will show side by side.