Reply
tgjones43
Helper IV
Helper IV
Partially syndicated - Outbound

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

Syndicated - Outbound

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

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

5 REPLIES 5
steph1234
Regular Visitor

Syndicated - Outbound

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

Syndicated - Outbound

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

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Syndicated - Outbound

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!

Syndicated - Outbound

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?

Syndicated - Outbound

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

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)