首页 文章

DAX累计和,按x周期重置

提问于
浏览
0

我有一个累积和函数如下:

Actions closed cumulative =
IF(MAX(Dates[Date])<CALCULATE(MIN(Dates[Date]),
        FILTER(all(Dates),Dates[PeriodFiscalYear]=[CurrentPeriod1])),
        CALCULATE(Actions[Actions closed on time],
            FILTER(ALL(Dates),
            Dates[Date]<=max(Dates[Date])
                            )
))

CurrentPeriod1是我们所处的时期,返回的内容如下:

PeriodFiscalYear | Actions | Actions Closed Cumulative
P01-2018/19      | 4       | 608
P02-2018/19      | 19      | 627
P03-2018/19      |  17     | 644        
P04-2018/19      |  6      | 650
P05-2018/19      |  7      | 657

所以它基本上计算了当前表中关闭的所有操作,但我想重置一定数量的时段,例如3个时段:

PeriodFiscalYear | Actions     | Actions Closed Cumulative    
P12-2017/18      | 10          |
P13-2017/18      | 10          |  
P01-2018/19      | 4           | 24 
P02-2018/19      | 19          | 33 
P03-2018/19      |  17         | 40      
P04-2018/19      |  6          | 42
P05-2018/19      |  7          | 30

尽管阅读量很大,但我很难理解如何做到这一点 . 我有一个日历表,每年有13个时段的日期,几乎每个你能想到的措施,月,月,月期等等 . 任何帮助将不胜感激 . 最终目标是在一定数量的时期内的移动平均线 .

谢谢

1 回答

  • 1

    假设您的 Actions 表使用日期值并且句点存储在 Dates 表中,我建议首先为句点创建一个索引列,以便它们更容易使用:

    PeriodIndex = 100 * VALUE(MID(Dates[PeriodFiscalYear], 5, 4)) +
                        VALUE(MID(Dates[PeriodFiscalYear], 2, 2))
    

    例如,这些索引值应该是看起来像 201804 而不是 P04-2018/19 的整数 .

    现在您已经使用了索引列,您可以像这样编写滚动累积总和:

    Trailing3Periods = 
        VAR CurrentPeriod = MAX(Dates[PeriodIndex])
        RETURN CALCULATE(SUM(Actions[Actions closed on time]),
                   FILTER(ALL(Dates),
                       Dates[PeriodIndex] <= CurrentPeriod &&
                       Dates[PeriodIndex] > CurrentPeriod - 3))
    

相关问题