MDX:如何根据top count获取上期?

MDX: How to get the previous period based on top count?

我必须计算今年的前 10 个品牌,然后得到去年的相同数字......但我发现它有点棘手。

我有以下一组今年迄今排名前 10 的品牌。

我的日期是一个参数(月-年),到目前为止一切正常。

filter(TopCount(
              ([10 - Brand].[Brand].Allmembers) * {STRTOMEMBER(@DATE)}
          ,10,
         [Measures].[Act YTD]
          ), [Measures].[Act YTD] <> null)

但是现在我必须要用这一套,弄到上一年的

预期结果是今年及以后,去年同查询的数字:

Year | Quarter |   Month   | Brand | Act YTD
2019 | 20193   |  Aug 2019 | BR01  | 150
2019 | 20193   |  Aug 2019 | BR02  | 250
2019 | 20193   |  Aug 2019 | BR03  | 350
2019 | 20193   |  Aug 2019 | BR04  | 450
2019 | 20193   |  Aug 2019 | BR05  | 550
2019 | 20193   |  Aug 2019 | BR06  | 650
2019 | 20193   |  Aug 2019 | BR07  | 750
2019 | 20193   |  Aug 2019 | BR08  | 850
2019 | 20193   |  Aug 2019 | BR09  | 950
2019 | 20193   |  Aug 2019 | BR10  | 1150

2018 | 20183   |  Aug 2018 | BR01  | 100
2018 | 20183   |  Aug 2018 | BR02  | 200
2018 | 20183   |  Aug 2018 | BR03  | 300
2018 | 20183   |  Aug 2018 | BR04  | 400
2018 | 20183   |  Aug 2018 | BR05  | 500
2018 | 20183   |  Aug 2018 | BR06  | 600
2018 | 20183   |  Aug 2018 | BR07  | 700
2018 | 20183   |  Aug 2018 | BR08  | 800
2018 | 20183   |  Aug 2018 | BR09  | 900
2018 | 20183   |  Aug 2018 | BR10  | 1000

我需要指导:)

您可以尝试使用 Union 和 Parallelperiod 函数,类似这样,具体取决于日期维度、层次结构和级别的名称:

Union(filter(TopCount(
              ([10 - Brand].[Brand].Allmembers) * {STRTOMEMBER(@DATE)}
          ,10,
         [Measures].[Act YTD]
          ), [Measures].[Act YTD] <> null)
,
filter(TopCount(
              ([10 - Brand].[Brand].Allmembers) * {PARALLELPERIOD([Date].[Calendar Year].[Calendar Year], 1, STRTOMEMBER(@DATE))}
          ,10,
         [Measures].[Act YTD]
          ), [Measures].[Act YTD] <> null))

我找到了解决方案。

我现在将结果显示为列,而不是按行显示。

由于行分组和列分组,我不得不重新设计报表。

这样我就可以根据今年的日期创建前 10 个集合并获得 Y-1 度量值。

Year | Quarter |   Month   | Brand | Act YTD | Act YTD -1 | 
2019 | 20193   |  Aug 2019 | BR01  | 150     | 100        | 
2019 | 20193   |  Aug 2019 | BR02  | 250     | 200        | 
2019 | 20193   |  Aug 2019 | BR03  | 350     | 300        | 
2019 | 20193   |  Aug 2019 | BR04  | 450     | 400        | 
2019 | 20193   |  Aug 2019 | BR05  | 550     | 500        | 
2019 | 20193   |  Aug 2019 | BR06  | 650     | 600        | 
2019 | 20193   |  Aug 2019 | BR07  | 750     | 700        | 
2019 | 20193   |  Aug 2019 | BR08  | 850     | 800        | 
2019 | 20193   |  Aug 2019 | BR09  | 950     | 900        | 
2019 | 20193   |  Aug 2019 | BR10  | 1150    | 1000       |