【问题标题】:MDX : calculated measure gives different result with "where" and "from select"MDX :计算的度量给出不同的结果,“where”和“from select”
【发布时间】:2016-10-07 08:56:07
【问题描述】:

我的 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% 不正确

有人能解释一下区别吗?

【问题讨论】:

  • 我将在这个周末回答,这是 MDX 的复杂性之一,被覆盖的层次结构。需要一些时间才能使用,在其中定义元组,更改它们的计算方式。您也可以尝试 where 选项,它更接近第一个版本

标签: mdx iccube


【解决方案1】:

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

问题是如何解决这个表达式:

[Ambu].[Ambu].current

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

两种可能的解决方案

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

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

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

不过,我还是会仔细检查我的陈述。

【讨论】:

    【解决方案2】:

    我尝试了 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'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多