DAX - formula referencing itself

后端 未结 1 731
礼貌的吻别
礼貌的吻别 2020-12-20 01:02

I am struggling to recreate the following Excel logic in DAX:

Cont and CF are both data columns (sourced from SQL database), while

相关标签:
1条回答
  • 2020-12-20 01:20

    You cannot recursively self-reference a column in DAX.

    See this related question: Recursion in DAX

    However, for this particular case, you can create a closed-form formula for the column you want by realizing that for year N, the result you want can be written as

    A * AR^N + sum_(i=1)^N AR^(N-i) (Cont_i - CF_i)
    

    In DAX this can be written as follows (where Yr = N and JP[Year] = i):

    mA = 
    VAR AR = 1.03
    VAR Yr =  SELECTEDVALUE ( JP[Year] )
    VAR Temp =
        ADDCOLUMNS (
            FILTER ( ALL ( JP ), JP[Year] <= Yr ),
            "Const", ( JP[Cont] - JP[CF] ) * POWER ( AR, Yr - JP[Year] )
        )
    RETURN
        A[Parameter Value] * POWER ( AR, Yr ) + SUMX ( Temp, [Const] )
    

    If you're starting with 2021, then you'll need to subtract 2020 from the Yr variable.

    0 讨论(0)
提交回复
热议问题