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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

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

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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