我正在开发一个生成MDX的查询构建器应用程序,并尝试使用以下方法从多维数据集中获取客户计数,这很好用:
WITH MEMBER MEASURES.X AS (
{ [Customer].[Gender].[Female]},
[Customer].[Customer].Children
).Count
SELECT Measures.X ON 0 FROM [Adventure Works]
但是,如果用户拖入与客户无关的维度,例如:
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]
计数结果显然变得不正确。
有没有办法确定维度是否与客户相关,以便我可以将其从生成的MDX查询中排除?
答案 0 :(得分:1)
答案 1 :(得分:1)
使用Exists( Set_Expression1 , Set_Expression2 [, MeasureGroupName] )函数解决了问题。无需手动确定哪些维度相关。 Exists函数过滤掉不相关的元组,只留下。{3}}函数
{ [Customer].[Customer].Children, [Customer].[Gender].[Female]}
开始计算。
这是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]