如何在DAX Excel PowerPivot或Power BI中使用滚动/移动条件进行测量

如何在DAX Excel PowerPivot或Power BI中使用滚动/移动条件进行测量,excel,powerbi,dax,powerpivot,Excel,Powerbi,Dax,Powerpivot,我有这张桌子: 时期 坚定的 部门 净利润增长 资产 2018年12月31日 AA 1. 10 100 2018年12月31日 BB 1. 20 100 2018年12月31日 科科斯群岛 2. 30 100 2018年12月31日 DD 2. 40 100 2019年12月31日 AA 1. 15 100 2019年12月31日 BB 1. 25 100 2019年12月31日 科科斯群岛 2. 35 100 2019年12月31日 DD 2. 45 100 2020年12月31日 AA 1.

我有这张桌子:

时期 坚定的 部门 净利润增长 资产 2018年12月31日 AA 1. 10 100 2018年12月31日 BB 1. 20 100 2018年12月31日 科科斯群岛 2. 30 100 2018年12月31日 DD 2. 40 100 2019年12月31日 AA 1. 15 100 2019年12月31日 BB 1. 25 100 2019年12月31日 科科斯群岛 2. 35 100 2019年12月31日 DD 2. 45 100 2020年12月31日 AA 1. 18 100 2020年12月31日 BB 1. 无效的 100 2020年12月31日 科科斯群岛 2. 38 100 2020年12月31日 DD 2. 48 无效的
一种可能的解决方案是准备一个包含上一年设置的表变量,在本年计算中用作过滤器

ROA = 
VAR CurrentPeriod =
    SELECTEDVALUE ( T[Period] )
VAR PreviousPeriod =
    DATEADD (
        T[Period],
        -1,
        YEAR
    )
VAR Result =
    IF (
        NOT ISBLANK( CurrentPeriod ),
        VAR PreviousYearSet =
            CALCULATETABLE (
                SUMMARIZE (
                    T,
                    T[Sector],
                    T[Firm]
                ),
                NOT ISBLANK ( T[Assets] ),
                NOT ISBLANK ( T[Net Income] ),
                T[Period] = PreviousPeriod
            )
        RETURN
            CALCULATE (
                DIVIDE (
                    SUM ( T[Net Income] ),
                    SUM ( T[Assets] )
                ),
                NOT ISBLANK ( T[Assets] ),
                NOT ISBLANK ( T[Net Income] ),
                PreviousYearSet
            )
    )
RETURN
    Result
应用于样本数据的这一度量可以在矩阵可视化中使用,以给出预期结果