S
S
Shedal2012-08-21 17:55:47
SQL Server
Shedal, 2012-08-21 17:55:47

WHERE inside a calculated measure? (MDX/OLAP)?

I create a cube in SQL Server Analysis Services; the following problem arose.
There is a dimension D and a measure M, connected as many-to-many (which is important).
I need to define a calculated measure using the formula M/Σ(M), where Σ is the sum of all the measure facts associated with at least one member of the current dimension. For example, I have a total for measure M of about 3,000,000, while the following query returns about 120,000:

SELECT [Measures].[M] ON 0
FROM [MyCube]
WHERE [D].[All].CHILDREN

As you can see from the example, I learned how to calculate the correct sum separately - all you need to do is take not the whole cube, but its slice, limited by all members of the dimension.
But here's how to calculate this amount inside a calculated measure? Here is a simplified query example that I thought would work:
CREATE MEMBER [Measures].[Calc] AS
  [Measures].[M] / ( DRILLUPLEVEL( AXIS( 1 ).ITEM( 0 ).HIERARCHY.MEMBERS ).ITEM( 0 ), [Measures].[M] )
  WHERE DRILLUPLEVEL( AXIS( 1 ).ITEM( 0 ).HIERARCHY.MEMBERS ).ITEM( 0 ).CHILDREN

But of course MDX doesn't allow WHERE in a MEMBER declaration.
Can you please tell me if there are other ways to limit a slice for a calculated measure?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shedal, 2012-08-24
@Shedal

As a result, I came to the following universal solution:

CREATE HIDDEN [Total M] =
  AGGREGATE(
    DESCENDANTS(
      AXIS( 1 ).ITEM( 0 ).DIMENSION.LEVELS( 0 ).ITEM( 0 ),
      AXIS( 1 ).ITEM( 0 ).DIMENSION.LEVELS.COUNT
    ) - AXIS( 1 ).ITEM( 0 ).DIMENSION.LEVELS( 0 ).ITEM( 0 ),
    [Measures].[M]
  );

In short, we subtract the root member from the set of members of our dimension, and aggregate our measure over the remaining set.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question