开发者

How can I determine whether dimensions are related?

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
开发者_JS百科).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?


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


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜