MDX的年度化

时间:2016-10-26 08:59:15

标签: mdx

简介 目前,我正在对年度化另一个(YTD)指标的措施进行维护工作。措施的粒度是月份。年度化在月级上工作正常,但是当我们在日期层次中使用父项时,计算不起作用。

它应该像这样工作:

MeasureAnnualized = YTDMeasure * (CurrentMonth / 12)

CurrentMonth实现为

ClosingPeriod([Date].[DateHierarchy].[Month], [Date].[DateHierarchy]).MemberValue

月份级别可以正常使用:

Month       MeasureYTD  MeasureAnnualized   ClosingPeriod
july        -50        -85,71               7
august      -60        -90,00               8
september   (null)      (null)              9

但是在DateHierarchy的更高级别上,这不起作用。例如,在季度级别:

 
Quarter     MeasureYTD  MeasureAnnualized           ClosingPeriod
3           -60         -80,00 (should be : -90,00) 9 (should be: 8)

正如你所看到的,它选择了第3季(= 9)的ClosingPeriod,而这应该是最后一个"非空" ClosingPeriod(= 8)。这同样适用于年级:

Year        MeasureYTD  MeasureAnnualized           ClosingPeriod
2016        -60         -60,00 (should be : -90,00) 12 (should be: 8)

因此问题是:如何让这个ClosingPeriod成为YTD度量不是(null)的最后一个时期?

1 个答案:

答案 0 :(得分:0)

ClosingPeriod的msdn上的定义中,它给出了相同逻辑的等效嵌套版本:

Tail(Descendants(Member_Expression, Level_Expression), 1)

以下内容与添加NonEmpty

相似
WITH 
  MEMBER Measures.[LastNonEmpty] AS 
    Tail
    (
      NonEmpty
      (
        (EXISTING 
          [Date].[Calendar].[Month])
       ,[Measures].[Internet Sales Amount]
      )
     ,1
    ).Item(0).MemberValue 
SELECT 
  Measures.[LastNonEmpty] ON 0
 ,[Date].[Calendar].[Calendar Year].MEMBERS ON 1
FROM [Adventure Works];

返回以下内容:

enter image description here