Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MDX query containing 2 dimensions from the same Hierarchy

Tags:

mdx

adomd.net

The relevant structures from my cube are that I have a Hierarchy with "Class" and "SubClass". I also have a Measure called "Value" which is what im trying to obtain.

A simple query may look like:

SELECT
 NON EMPTY ([Measures].[Value]) ON COLUMNS,
 NON EMPTY ([Some Dimension].[Class Hierarchy].[Class]) ON ROWS
FROM [MyCube]

And I can obviously read the SubClass using the HIerarchy which is returned to Adomd.

My issue is twofold, firstly how would I "flatten" this hierarchy so as to receive both Class and SubClass as discrete members in the CellSet? This does not work:

SELECT
 NON EMPTY ([Measures].[Value]) ON COLUMNS,
 NON EMPTY (
   [Some Dimension].[Class Hierarchy].[Class], 
   [Some Dimension].[Class Hierarchy].[Sub Class]
) ON ROWS
FROM [MyCube]

The Class Hierarchy hierarchy is used more than once in the Crossjoin function

Second issue, what I actuually need to do is filter the above on particular classes, again this wont work for the same reason as above.

SELECT
 NON EMPTY ([Measures].[Value]) ON COLUMNS,
 NON EMPTY (
   {[Some Dimension].[Class Hierarchy].[Class].&[ClassA],[Some Dimension].[Class Hierarchy].[Class].&[ClassB]}, 
   [Some Dimension].[Class Hierarchy].[Sub Class]
) ON ROWS
FROM [MyCube]

Any help much appreciated. MDX is driving me nuts!

like image 584
Jamiec Avatar asked Dec 07 '09 16:12

Jamiec


People also ask

What is the difference between SQL query and MDX query?

In SQL the SELECT list is derived from tables and the FROM clause is also directly on tables. On the other hand in MDX the SELECT list derived from dimensions but unlike SQL the FROM clause is always on the cube not on dimensions.

Why can’t I select from more than one table in MDX?

As a result MDX requires that you always explicitly specify a display axis for all elements in the SELECT list. In SQL if you select from two or more tables you have to explicitly join the tables with a “JOIN” word.

How to cross join multiple sales territory sets in MDX?

Another thing to note is that, I derived the first Sales Territory set from attribute hierarchies and the second set from user-defined hierarchy in the Sales Territory dimension. This is because MDX expects the sets you are cross joining to always come from different hierarchies. You can cross join multiple set by nesting cross joins as below.

What is the difference between mdx1 and mdx2 tuples?

In listing8 below, the two tuples on ROWS in MDX1 has the same number and ordering of the dimension members. On the other hand the number of dimension members in the two tuples on the ROWS axis in MDX2 does not conform. The second tuple has only two dimension members as oppose to three in the first tuple so it fails when you execute it. Listing8.


1 Answers

You are missing the MEMBERS property on your dimension.

For your first example try this:

SELECT 
    NON EMPTY ([Measures].[Value]) ON COLUMNS,
    NON EMPTY {(
            [Some Dimension].[Class Hierarchy].[Class].MEMBERS,
            [Some Dimension].[Class Hierarchy].[Sub Class].MEMBERS)} ON ROWS
FROM [MyCube]

For your second example try this:

SELECT 
    NON EMPTY ([Measures].[Value]) ON COLUMNS, 
    NON EMPTY {(
            [Some Dimension].[Class Hierarchy].[Class].&[ClassA],
            [Some Dimension].[Class Hierarchy].[Class].&[ClassB],
            [Some Dimension].[Class Hierarchy].[Sub Class].MEMBERS)} ON ROWS
FROM [MyCube]
like image 90
jvilalta Avatar answered Sep 16 '22 13:09

jvilalta