简体   繁体   English

计算度量中的MDX LAG命令返回错误值

[英]MDX LAG Command in Calculated Measure return wrong value

I have following query 我有以下查询

 with member priorSellOut as ([Date].[Year Month].CurrentMember.LAG(1),MEASURES.[Sell Out]) Select { MEASURES.[Sell Out] ,PriorSellOut } ON COLUMNS, [Date].[Year Month].[Year Month].Members ON ROWS From Sales 

the result of this query is: 该查询的结果是:

  Sell Out Prior Sell Out 2018.01 34329 (null) 2018.02 37752 34329 2018.03 21798 37752 2018.04 41477 21798 2018.05 50125 41477 2018.06 6363 50125 2018.07 11511 6363 2018.08 7444 11511 2018.09 13989 7444 2018.10 1936 13989 

I want to have last 3 month ago. 我要过去三个月前。 and use [3 Month Ago] named set.following query: 并使用[3个月前]命名为set.following查询:

 with member priorSellOut as ([Date].[Year Month].CurrentMember.LAG(1),MEASURES.[Sell Out]) Select { MEASURES.[Sell Out] ,PriorSellOut } ON COLUMNS, [Date].[Year Month].[Year Month].Members ON ROWS From Sales Where ([3 Month Ago]) 

the result of this query is: 该查询的结果是:

  Sell Out Prior Sell Out 2018.08 7444 (null) 2018.09 13989 7444 2018.10 1936 13989 

I want to have following result. 我想得到以下结果。 Prior Sell Out Column for 2018.08 must have value. 2018.08的先前售罄专栏必须具有价值。

  Sell Out Prior Sell Out 2018.08 7444 11511 2018.09 13989 7444 2018.10 1936 13989 

Thanks in advance 提前致谢

Your problem is that instead of filtering on the list of rows to display, you instead filter out all data that is not in the last 3 months. 您的问题是,不是过滤要显示的行列表,而是过滤掉了最近三个月以外的所有数据。

To filter out the rows - just apply a limited set expression to the axis. 要过滤出行-只需在轴上应用有限的设置表达式即可。 We want the last 3 months to be displayed, so let's take the last three members of the months list like so: TAIL([Date].[Year Month].[Year Month].Members,3) . 我们希望显示最近的3个月,所以让我们像这样查看月份列表的最后3个成员: TAIL([Date]。[Year Month]。[Year Month] .Members,3) Now we can safely remove the WHERE clause. 现在我们可以安全地删除WHERE子句了。 The result is: 结果是:

with member priorSellOut as
  ([Date].[Year Month].CurrentMember.LAG(1),MEASURES.[Sell Out])
Select 
  {
      MEASURES.[Sell Out]
      ,PriorSellOut
  } ON COLUMNS,
  TAIL([Date].[Year Month].[Year Month].Members,3) ON ROWS
From Sales

NOTE: This assumes that the [Date].[Year Month].[Year Month] dimension IS PROPERLY ORDERED 注意:这假设[Date]。[Year Month]。[Year Month]维度是正确排序的

EDIT: If you really necessary need to use the [3 Month Ago] named set - just put it on the axis instead of the TAIL(...) formula I used. 编辑:如果确实需要使用[3个月前]命名集-只需将其放在轴上,而不是我使用的TAIL(...)公式即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM