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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
tonyclifton
Helper III
Helper III

Calculate Average of current and previous two years

Hello community,


I have the following (simplified) data. I want to calculate the average of three years based on below table and show that value for the according year:

 

YearYearQuarterValue
20132013-0120
20132013-0240
20132013-0335
20132013-0410
20142014-0144
20142014-0216
20142014-0315
20142014-0410
20152015-0161
20152015-0235
20152015-0322
20152015-0420


And this would be the expected output for 2015:

YearValueAverage of 3 years
2013105
201485
2015138109

 

109 = (105 + 85 + 138) / 3

 

I hope you have an idea here because I am stuck.

Thank you.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @tonyclifton 

Please check the below picture and the sample pbix file's link down below.

 

Picture2.png

 

Value Total Measure =
SUM('Table'[Value])
 
Avg of 3 years =
VAR currentyear =
MAX ( 'Table'[Year] )
RETURN
IF (
currentyear - 1
< MINX ( ALL ( 'Table'[Year] ), 'Table'[Year] )
|| currentyear - 2
< MINX ( ALL ( 'Table'[Year] ), 'Table'[Year] ),
BLANK (),
AVERAGEX (
CALCULATETABLE (
VALUES ( 'Table'[Year] ),
FILTER (
ALL ( 'Table' ),
'Table'[Year] >= currentyear - 2
&& 'Table'[Year] <= currentyear
)
),
[Value Total Measure]
)
)
 
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi, @tonyclifton 

Please check the below picture and the sample pbix file's link down below.

 

Picture2.png

 

Value Total Measure =
SUM('Table'[Value])
 
Avg of 3 years =
VAR currentyear =
MAX ( 'Table'[Year] )
RETURN
IF (
currentyear - 1
< MINX ( ALL ( 'Table'[Year] ), 'Table'[Year] )
|| currentyear - 2
< MINX ( ALL ( 'Table'[Year] ), 'Table'[Year] ),
BLANK (),
AVERAGEX (
CALCULATETABLE (
VALUES ( 'Table'[Year] ),
FILTER (
ALL ( 'Table' ),
'Table'[Year] >= currentyear - 2
&& 'Table'[Year] <= currentyear
)
),
[Value Total Measure]
)
)
 
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hey there,

 

Is there a way that this would work to have it per month rather than per year?

Hi, 

Thank you for your message, and please provide a sample pbix file with how the expected outcome looks like, and then I can try to look into it.

Thank you.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thank you very much @Jihwan_Kim . This works perfectly.

selimovd
Super User
Super User

Hey @tonyclifton ,

 

depending if you want to calculate whole years or from the max date or filter date you can use different approaches.

Check the function DATESINPERIOD function (DAX) - DAX | Microsoft Docs or PARALLELPERIOD function (DAX) - DAX | Microsoft Docs that can both extend the filter context of your date to 3 years.

 

Also be aware you need a proper date table in order to make the time intelligence functions work:

https://softcrylic.com/blogs/power-bi-for-beginners-how-to-create-a-date-table-in-power-bi/

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors