Forum Discussion

CJ_96601's avatar
CJ_96601
Helper V
5 years ago
Solved

Add sales based on dynamic year selection

Hello, 

 

Can i ask someone to help out on this requirements.

Spoiler
Add sales based on year selected (filters)
YearSales Year Selection 
2010100 If year 2013 is selected in filter 
2011200 2013 then add year 2013 , year 2012, and year 2011 sales
2012300 Result900
2013400   
2014500 If year 2020 is selected in filter 
2015600 2020then add year 2020, 2019, and 2018  sales
2016700 Result3100
2017800   
2018900   
20191000   
20201200   
20211300   

 

 

thanks

  • CJ_96601 , Create a separate year table( Say Date) and join on year , and try a formula like

     

    rolling = CALCULATE(sum('Table'[sales]),filter(ALL('Date'),'Date'[Year]>=max('Date'[Year])-3 && 'Date'[Year]<=max('Date'[Year])) )

     

    in case you need a trend display  then do join the year table

    measure =
    var _max = maxx(allselected('Date'), 'Date'[Year])
    return
    calculate(sum('Table'[sales]), filter(Table, Table[Year] >= _max -3 && Table[Year] <= _max))

     

    Use -2, in place -3

3 Replies

  • CJ_96601 , Create a separate year table( Say Date) and join on year , and try a formula like

     

    rolling = CALCULATE(sum('Table'[sales]),filter(ALL('Date'),'Date'[Year]>=max('Date'[Year])-3 && 'Date'[Year]<=max('Date'[Year])) )

     

    in case you need a trend display  then do join the year table

    measure =
    var _max = maxx(allselected('Date'), 'Date'[Year])
    return
    calculate(sum('Table'[sales]), filter(Table, Table[Year] >= _max -3 && Table[Year] <= _max))

     

    Use -2, in place -3

  • v-deddai1-msft's avatar
    v-deddai1-msft
    Community Support

    Hi CJ_96601 ,

     

    Would you please try the following measure:

    Measure = CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),'Table'[Year]<=MAX('Table'[Year])&&'Table'[Year]>MAX('Table'[Year])-3))

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    Best Regards,

    Dedmon Dai