MDX :计算的度量给出 "where" 和 "from select" 不同的结果

MDX : calculated measure gives different result with "where" and "from select"

我有 2 个 MDX 语句有问题,第一个给出了正确的结果,但第二个与预期的不同。

由于 MDX 是动态构建的,所以我宁愿使用第二个。

create calculated member [Sejours Ambulatoire] as sum([Ambu].[Ambu].[Ambu].[Ambulatoire], NbSejours)
create calculated member [Taux Ambulatoire] as IIF( [Ambu].[Ambu].current is [Ambu].[Ambu].[Non Ambulatoire], 0, divN([Sejours Ambulatoire], [Measures].[NbSejours] , 0)   ), format_string='percent'

第一个代码:

select [Measures].[Taux Ambulatoire] on 0
from [Cube]
where  {[Ambu].[Ambu].[Non Ambulatoire]} * {[Etablissement].[Lieu établissement].[All-M].&[CHU de Brest]} * { [Periode].[Periode].[All-M].&[2014] }

-- 结果 0,00% 正确

第二个代码:

SELECT
 { [Measures].[Taux Ambulatoire] }  ON 0
 FROM ( SELECT
{ [Periode].[Periode].[All-M].&[2014] } ON 0,
{ [Etablissement].[Lieu établissement].[All-M].&[CHU de Brest] } ON 1,
{ [Ambu].[Ambu].[Non Ambulatoire] } ON 2
     FROM [Cube])

-- 结果 120,86% 不正确

谁能解释一下区别?

不要忘记,在 icCube 中,您有一个 MDX 调试器,可以帮助您了解如何解决 MDX 语句的不同部分。

问题是这个表达式是怎么解的:

[Ambu].[Ambu].current

当前不是从子选择过滤器定义中获取值。它从其他来源获取值:计算成员中定义的 where 子句、轴和元组。

两种可能的解决方案

1) 将过滤器放在 where 子句中而不是过滤器中,因此 current 将 return where 子句中定义的元组。

2) 要使 IIF 正常工作,您可以使用 GetFilterInfo 函数,该函数 return 是子选择的内容和 where 子句

isIn( GetFilterInfo([Ambu].[Ambu]) , [Ambu].[Ambu].[Non Ambulatoire] )

尽管如此,我还是会仔细检查我的声明。

我尝试了 iSin(GetFilterInfo()) 建议。

with member [Taux Ambulatoire Test] as iif(isIn( GetFilterInfo([Ambu].[Ambu]) , [Ambu].[Ambu].[Non Ambulatoire] ), 0, divN([Sejours Ambulatoire], [Measures].[NbSejours] , 0)   ), format_string='percent'
SELECT
 { [Measures].[Taux Ambulatoire Test] }  ON 0
, [Ambu].[Ambu] on 1
 FROM ( SELECT
{ [Periode].[Periode].[All-M].&[2014] } ON 0,
{ [Etablissement].[Lieu établissement].[All-M].&[CHU de Brest] } ON 1
--,{ [Ambu].[Ambu].[Non Ambulatoire] } ON 2
     FROM [Cube])

效果更好,但在我想要获得所有 [Ambu] 的情况下。[Ambu] 行,我仍然获得 NonAmbulatoire 的 120,86%...

我找到的唯一解决方案是为 SejoursNonAmbulatoire 创建一个度量。然后 [Taux Ambulatoire] 正在检查整个选择是否为 NonAmbulatoire...

create calculated member [Sejours Ambulatoire] as sum([Ambu].[Ambu].[Ambu].[Ambulatoire], NbSejours)
create calculated member [Sejours NONAmbulatoire] as sum([Ambu].[Ambu].[Ambu].[Non Ambulatoire], NbSejours)
create calculated member [Taux Ambulatoire] as IIF( [Sejours NONAmbulatoire] = [Measures].[NbSejours], 0, divN([Sejours Ambulatoire], [Measures].[NbSejours] , 0)   ), format_string='percent'