Question

I am developing a query builder application that generates MDX and trying to get customer counts from a cube using the following, which works just fine:

WITH MEMBER MEASURES.X AS (
    { [Customer].[Gender].[Female]}, 
    [Customer].[Customer].Children
).Count
SELECT Measures.X ON 0 FROM [Adventure Works]

However, if the user drags in a dimension that is not related to the customer like:

WITH MEMBER MEASURES.X AS (
    { [Customer].[Gender].[Female]}, 
    { [Employee].[Status].[Active], [Employee].[Status].[Inactive]},  
    [Customer].[Customer].Children
).Count
SELECT Measures.X ON 0 FROM [Adventure Works]

the count result obviously becomes incorrect.

Is there a way to determine whether a dimension is related to the customer so that I can exclude it from the generated MDX query?

Was it helpful?

Solution 2

Solved the problem by using the Exists( Set_Expression1 , Set_Expression2 [, MeasureGroupName] ) function. No need to manually determine which dimensions are related. The Exists function filters out the unrelated tuples, leaving only the { [Customer].[Customer].Children, [Customer].[Gender].[Female]} set to do the count over.

Here is the MDX:

WITH MEMBER MEASURES.X AS Exists(
    [Customer].[Customer].Children,
    {[Customer].[Gender].[Female]}
    *
    {[Employee].[Status].[Active], [Employee].[Status].[Inactive]}
).Count
SELECT Measures.X ON 0 FROM [Adventure Works]

OTHER TIPS

This information can be retrieved from the cube through AMO. The Cube class contains all the cube metadata you'll need.

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