Forum Discussion
Hide previous years on x axis but keep average calculation
- 10 months ago
Hi KCfromDC ,
Apologies for the incorrection I have done - 5 years on the formula and should be minus -4 years to get current year + 4 that gives 5 years.
If you do the math:
105 + 136 + 123 + 90 +122 +107 = 683 / 6 = 113.83
Redo the formula to:
Notifications prev 5 years avg = VAR _TempTable = ADDCOLUMNS ( CALCULATETABLE ( VALUES ( 'Dates'[Year] ), REMOVEFILTERS ( 'Dates'[Year] ) ), "Notifications", [Notifications count] ) RETURN AVERAGEX ( FILTER ( _TempTable , 'Calendar'[Year] <= MAX ( 'Dates'[Year] ) && 'Calendar'[Year] >= MAX ( 'Dates'[Year] ) - 4 ), [Notifications] )This should get expected result
Thanks! I changed the Return function to be 'Dates'[Year] as that's my date table. However, it's giving me the wrong values.
Here's what I get in Excel (using values back to 2010)
| Year | Count | 5 year average |
| 2010 | 105 | |
| 2011 | 136 | |
| 2012 | 123 | |
| 2013 | 90 | |
| 2014 | 122 | |
| 2015 | 107 | 115.2 |
| 2016 | 130 | 115.6 |
| 2017 | 130 | 114.4 |
| 2018 | 150 | 115.8 |
| 2019 | 134 | 127.8 |
| 2020 | 152 | 130.2 |
| 2021 | 185 | 139.2 |
| 2022 | 134 | 150.2 |
| 2023 | 180 | 151 |
| 2024 | 176 | 157 |
The below is from PowerBI. The original column is calculating correctly from 2015-2024 (since it's not able to "see" the 2014 and earlier 5 year average, e.g. 2009-2013, 2008-2012, etc.), but the new column using the code you provided is incorrect. 🤔
This is a tough one, I appreciate the assistance!
- MFelix10 months ago
Super User
Hi KCfromDC ,
Apologies for the incorrection I have done - 5 years on the formula and should be minus -4 years to get current year + 4 that gives 5 years.
If you do the math:
105 + 136 + 123 + 90 +122 +107 = 683 / 6 = 113.83
Redo the formula to:
Notifications prev 5 years avg = VAR _TempTable = ADDCOLUMNS ( CALCULATETABLE ( VALUES ( 'Dates'[Year] ), REMOVEFILTERS ( 'Dates'[Year] ) ), "Notifications", [Notifications count] ) RETURN AVERAGEX ( FILTER ( _TempTable , 'Calendar'[Year] <= MAX ( 'Dates'[Year] ) && 'Calendar'[Year] >= MAX ( 'Dates'[Year] ) - 4 ), [Notifications] )This should get expected result