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
dc7669
Resolver I
Resolver I

How to write a Measure that will sum up previous 5 year of data?

Hi, 

 

After some manipulation, I got the below table under "Transform" in PowerBI.

 

FiscalYearAreaCOUNTYCategoryCounts
2011Region 5       Atkinson                 Land Clearing279
2010Region 5       Atkinson                 Agriculture78
2018Region 2       Baldwin                  Land Clearing359
2013Region 5       Atkinson                 Agriculture74
2013Region 2       Baldwin                  Silviculture60
2020Region 2       Baldwin                  Silviculture27
2011Region 2       Baldwin                  Silviculture53
2018Region 2       Baldwin                  Agriculture43
2011Region 5       Atkinson                 Agriculture118
2009Region 5       Atkinson                 Land Clearing101
2014Region 5       Atkinson                 Agriculture73
2014Region 5       Atkinson                 Land Clearing302
2022Region 5       Atkinson                 Silviculture7
2017Region 2       Baldwin                  Land Clearing330
2012Region 5       Atkinson                 Land Clearing586
2020Region 2       Baldwin                  Agriculture10
2017Region 5       Atkinson                 Silviculture233
2009Region 2       Baldwin                  Agriculture39
2005Region 2       Baldwin                  Land Clearing394
2012Region 5       Atkinson                 Agriculture88
2010Region 5       Atkinson                 Land Clearing381
2015Region 5       Atkinson                 Land Clearing460
2013Region 5       Appling                  Land Clearing1210
2007Region 5       Appling                  Silviculture1
2013Region 5       Atkinson                 Silviculture193
2022Region 5       Appling                  Land Clearing9
2020Region 5       Atkinson                 Land Clearing157
2015Region 5       Appling                  Silviculture400
2012Region 5       Appling                  Agriculture232
2010Region 5       Appling                  Agriculture214
2008Region 2       Baldwin                  Agriculture16
2011Region 2       Baldwin                  Agriculture87
2017Region 5       Appling                  Agriculture155
2015Region 2       Baldwin                  Agriculture67
2014Region 2       Baldwin                  Silviculture47
2008Region 2       Baldwin                  Silviculture53
2021Region 5       Atkinson                 Land Clearing140
2017Region 5       Appling                  Land Clearing931
2020Region 5       Appling                  Silviculture330
2016Region 5       Appling                  Land Clearing1037
2019Region 2       Baldwin                  Land Clearing275
2023Region 5       Appling                  Silviculture1
2011Region 5       Appling                  Silviculture513
2020Region 5       Atkinson                 Silviculture237
2019Region 5       Atkinson                 Silviculture111
2015Region 5       Atkinson                 Silviculture156
2018Region 5       Appling                  Agriculture224
2012Region 5       Appling                  Silviculture587
2018Region 5       Appling                  Land Clearing856
2016Region 5       Atkinson                 Land Clearing401
2021Region 5       Appling                  Land Clearing820
2016Region 2       Baldwin                  Land Clearing236
2012Region 2       Baldwin                  Silviculture30
2016Region 5       Appling                  Agriculture174
2024Region 5       Appling                  Land Clearing3
2016Region 2       Baldwin                  Agriculture53
2019Region 5       Atkinson                 Land Clearing209
2012Region 5       Appling                  Land Clearing1064
2014Region 2       Baldwin                  Land Clearing405
2018Region 5       Appling                  Silviculture258
2010Region 5       Atkinson                 Silviculture138
2017Region 2       Baldwin                  Agriculture52
2005Region 5       Appling                  Land Clearing3
2015Region 5       Atkinson                 Agriculture62
2011Region 5       Appling                  Agriculture373
2020Region 5       Atkinson                 Agriculture50
2015Region 2       Baldwin                  Silviculture58
2013Region 5       Atkinson                 Land Clearing473
2011Region 5       Appling                  Land Clearing641
2019Region 2       Baldwin                  Agriculture35
2017Region 5       Appling                  Silviculture228
2018Region 5       Atkinson                 Land Clearing293
2006Region 2       Baldwin                  Agriculture5
2015Region 5       Appling                  Land Clearing1026
2019Region 2       Baldwin                  Silviculture72
2006Region 2       Baldwin                  Silviculture6
2014Region 2       Baldwin                  Agriculture69
2005Region 2       Baldwin                  Silviculture7
2014Region 5       Atkinson                 Silviculture171
2017Region 5       Atkinson                 Agriculture85
2012Region 5       Atkinson                 Silviculture92
2017Region 2       Baldwin                  Silviculture50
2017Region 5       Atkinson                 Land Clearing352
2019Region 5       Appling                  Agriculture124
2019Region 5       Appling                  Land Clearing739
2022Region 2       Baldwin                  Land Clearing4
2013Region 2       Baldwin                  Land Clearing380
2011Region 5       Atkinson                 Silviculture207
2018Region 2       Baldwin                  Silviculture61
2024Region 5       Atkinson                 Land Clearing1
2016Region 2       Baldwin                  Silviculture62
2011Region 2       Baldwin                  Land Clearing228
2013Region 2       Baldwin                  Agriculture57
2024Region 2       Baldwin                  Land Clearing3
2015Region 2       Baldwin                  Land Clearing240
2014Region 5       Appling                  Silviculture392
2021Region 5       Appling                  Agriculture155
2019Region 5       Atkinson                 Agriculture54
2022Region 5       Atkinson                 Agriculture2
2006Region 2       Baldwin                  Land Clearing566
2023Region 5       Atkinson                 Silviculture1
2020Region 5       Appling                  Land Clearing956
2015Region 5       Appling                  Agriculture178
2020Region 2       Baldwin                  Land Clearing287
2018Region 5       Atkinson                 Agriculture64
2009Region 5       Atkinson                 Silviculture15
2021Region 5       Atkinson                 Silviculture279
2007Region 2       Baldwin                  Agriculture3
2016Region 5       Atkinson                 Silviculture162
2012Region 2       Baldwin                  Land Clearing246
2021Region 5       Appling                  Silviculture249
2008Region 2       Baldwin                  Land Clearing1249
2014Region 5       Appling                  Agriculture241
2020Region 5       Appling                  Agriculture81
2010Region 2       Baldwin                  Silviculture77
2021Region 2       Baldwin                  Land Clearing382
2010Region 5       Appling                  Silviculture256
2009Region 2       Baldwin                  Silviculture69
2016Region 5       Appling                  Silviculture359
2016Region 5       Atkinson                 Agriculture61
2010Region 2       Baldwin                  Agriculture44
2021Region 2       Baldwin                  Agriculture31
2007Region 2       Baldwin                  Land Clearing497
2010Region 5       Appling                  Land Clearing1070
2012Region 2       Baldwin                  Agriculture30
2022Region 5       Atkinson                 Land Clearing3
2021Region 2       Baldwin                  Silviculture70
2021Region 5       Atkinson                 Agriculture44
2010Region 2       Baldwin                  Land Clearing562
2009Region 2       Baldwin                  Land Clearing758
2005Region 2       Baldwin                  Agriculture4
2013Region 5       Appling                  Agriculture237
2007Region 2       Baldwin                  Silviculture6
2019Region 5       Appling                  Silviculture237
2013Region 5       Appling                  Silviculture473
2018Region 5       Atkinson                 Silviculture140
2014Region 5       Appling                  Land Clearing1003
2022Region 5       Appling                  Silviculture5
2009Region 5       Atkinson                 Agriculture6

Now, I want to get Previous 5 year Average Counts for each row.  For sure, the previous 5-year average needs to be for the same County and same Category. 

 

I can do the following ito Add a Column.

List.Sum(
Table.SelectRows(
#"Grouped Rows",
(C) => C[FiscalYear] <= ([FiscalYear] -1) and (C[FiscalYear]>=([FiscalYear]-5)) and C[CATEGORY]=[CATEGORY] and C[COUNTY]=[COUNTY]
)[Counts]
)/5 

 

However, by putting the above step in, it will extend the Load time from under 15 minutes to over 3 hours! 

 

So, I would like to try to use a Measure to do the same thing. 

 

MeasurePre5Year =

CALCULATE(
SUM('Table'[Permits])/5,
FILTER(
ALL('Table'),
'Table'[FiscalYear] >= (MAX(Table[FiscalYear])- 5)
&& 'Table'[FiscalYear] < MAX(Table[FiscalYear])
&& 'Table'[Category] = MAX(Table[Category])
&& 'Table'[Area] = MAX(Table[Area])

)
)
 
The above would work and would calculate the previous 5-year Average Count for the Area.  But, it will not break down into County.  The MeasurePre5Year will show the MeasurePre5Year for the Area under each County row within the same Area.  
 
Can a Measure do what I wanted, showing the pre-5year acount for each County and sum up in Area?  
 
Thanks.
 
dc7669

 

2 ACCEPTED SOLUTIONS
DemoFour
Responsive Resident
Responsive Resident

Hay @dc7669  have a read through this function. DATESYTD - DAX Guide 

View solution in original post

FYI,  I think Measure will give us a value for each row.  But, if I want to roll up to show sum or average of a Meausre within a category, it may be impossible.   If I am wrong, please correct. 

 

So, the only thing I know to do is to use "Group By" in Transform.  

Then, roll up could be done easily.

 

Also, it seems to me that "Group by" steps often take a while to execute.  So, it is better to reduce the number of "Group by" steps in the calculation.

Further, it is better to create a View in SQL database to do the "Group By" and import the result into PowerBI, rather than have PowerBI do the "Group By" to reduce PowerBI's refresh time. 

 

dc7669

View solution in original post

3 REPLIES 3
dc7669
Resolver I
Resolver I

Hi @DemoFour ,

 

Thanks for the DATESYTD - DAX Guide , it will help me learn DAX. 

 

Following the link you provided, I saw this.   

dc7669_0-1709985549793.png

What if I want to break down the summary into Year AND Region AND/OR Category, how would I write the Measure? 

 

Using this DAX Code to write a measure on the data table above, 

MeasurePre5Year = 

CALCULATE(
SUM('Table'[Permits])/5,
FILTER(
ALL('Table'),
'Table'[FiscalYear] >= (MAX(Table[FiscalYear])- 5)
&& 'Table'[FiscalYear] < MAX(Table[FiscalYear])
&& 'Table'[Category] = MAX(Table[Category])
&& 'Table'[County] = MAX(Table[County])

)
)

I found that the roll up from County to Area will be using the last entry found in the County.  

dc7669_1-1709987091754.png

Is it possible to write make the roll up to show Sum or Average instead of the last one?  

 

Thanks. 

 

dc7669

FYI,  I think Measure will give us a value for each row.  But, if I want to roll up to show sum or average of a Meausre within a category, it may be impossible.   If I am wrong, please correct. 

 

So, the only thing I know to do is to use "Group By" in Transform.  

Then, roll up could be done easily.

 

Also, it seems to me that "Group by" steps often take a while to execute.  So, it is better to reduce the number of "Group by" steps in the calculation.

Further, it is better to create a View in SQL database to do the "Group By" and import the result into PowerBI, rather than have PowerBI do the "Group By" to reduce PowerBI's refresh time. 

 

dc7669

DemoFour
Responsive Resident
Responsive Resident

Hay @dc7669  have a read through this function. DATESYTD - DAX Guide 

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