Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tgjones43
Helper IV
Helper IV

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!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@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))

 

View solution in original post

5 REPLIES 5
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. 

amitchandak
Super User
Super User

@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))

 

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!

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?

OK now I understand the role of the date table, and the measure is now working for me. For anyone viewing this thread, this explains how to create a date table and why it is important in this scenario:

 

How to Create Date Tables in Power BI Tutorial | DataCamp

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.