Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Excel Formula to Dax

I have sample data in Excel  for few years .   year    value   2020      100   2021      120     2022      150     Syntax: ((currentyear)/(previousyear))^(1-n))-1   Excel  used the belo...
  • FreemanZ's avatar
    3 years ago

    hi Anonymous 

    seems you are calculating compound annual growth rate. 

    i tried the following, for your reference. 

    1) expand your dataset and transpose it to:

    YearValue
    201740
    201850
    201980
    2020100
    2021120
    2022150

     

    2) add a calculate table for the n parameter, like:

     

     

    n = 
    SELECTCOLUMNS(
        GENERATESERIES(1,5),
        "n", [Value]
    )

     

     

     

     

    3) plot a slicer with n[n] column and a table visual with year column and a measure like:

     

     

    CAGA% = 
    VAR _currentyear = MAX(data[Year])
    VAR _n = SELECTEDVALUE(n[n])
    VAR _firstyear = _currentyear-_n
    VAR rate = 
        DIVIDE(
            SUM(data[value]),
            CALCULATE(
                SUM(data[value]),
                data[Year]=_currentyear-_n
            )
        )^(1/_n)
        -1
    RETURN 
        IF(rate<>-1, rate, "")

     

     

     

    it worked like:

     

    verified the calculation with Excel formula: