Forum Discussion

tgjones43's avatar
tgjones43
Helper IV
3 years ago
Solved

3 year rolling average required

I've seen a few rolling average posts and YouTube videos but can't seem to find one that works for my dataset, which contains the concentration of elements in rivers.

I have frequent measurements of multiple parameters across many sites over many years. This is a snippet of what the data looks like (there are many more sites, elements and dates):

 

SiteElementDateConcentration
APhosphate05/01/20190.395
APhosphate06/04/20190.108
APhosphate03/07/20190.208
APhosphate08/10/20190.234
APhosphate01/02/20200.029
APhosphate11/06/20200.301
APhosphate01/08/20200.289
APhosphate23/11/20200.094
APhosphate03/01/20210.409
APhosphate04/04/20210.041
APhosphate05/08/20210.132
APhosphate09/11/20210.203

 

and the column at the end is what I would like to compute:

 

SiteElementYearAnnual Average3 year rolling average
APhosphate20190.236250.23625
APhosphate20200.178250.20725
APhosphate20210.196250.20358

 

so the 3 year rolling average for 2019 is the same as the annual average for 2019, because there isn't any data prior to that year, but the 3 year rolling average for 2021 is the average of all values from 2019-2021 inclusive.

Any help would be greatly appreciated!

  • tgjones43 , with help from date table

     

    3 Year Avg = CALCULATE(AverageX(Values('Date'[Year]),calculate(Average('Table'[Concentration] )))
    ,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,Year))

     

5 Replies

  • tgjones43 , with help from date table

     

    3 Year Avg = CALCULATE(AverageX(Values('Date'[Year]),calculate(Average('Table'[Concentration] )))
    ,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,Year))

     

    • tgjones43's avatar
      tgjones43
      Helper IV

      thanks amitchandak in my report the 3 year average is just matching the annual average. Would you mind attaching your pbix so I can try to figure out where I am going wrong?

    • tgjones43's avatar
      tgjones43
      Helper IV

      Hi amitchandak

       

      I have just realised this isn't performing the calculation as required, but that is my fault for not describing it properly. I think your solution is calculating the average value for each year, then calculating the average of those averages for the last 3 years. But I don't want it to calculate an average of averages, it should calculate an average from all the datapoints in that 3 year period.

       

      Would you be able to modify the formula to do that?

       

      Thank you!

  • steph1234's avatar
    steph1234
    Regular Visitor

    I was reading through this thread and was wondering what formula was used to calculate the annual average, if you could let me know that would be great.