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
kman5554
New Member

Average of Last n Months Daily Granularity

Hi all, 

 

Struggling with a problem for a couple of days so thought I would ask here.

 

I have a table of prices similar to the following (which spans 15 years):

 

DatePrice
1 Apr 202162.1876
2 Apr 202162.1876
3 Apr 202162.1876
4 Apr 202162.1876
5 Apr 202162.1876
6 Apr 202162.3674
7 Apr 202161.0276
8 Apr 202162.002
9 Apr 202162.2688
10 Apr 202162.2688
11 Apr 202162.2688
12 Apr 202162.5704
13 Apr 202163.0924
14 Apr 202165.6676
15 Apr 202165.5342

 

What I need to do is calculate the average for each individual month, then the average of the 9 previous months of each of those individual averaged months and display the data in daily format (so the value for each day in a given motnh will be the same). This is so I can plot this on a day granularity chart. To clarify, I've broken it doen into the main steps:

 

Obtaining average price for each month

Calculating the average of the previous 9 months for each given row (excluding current month)

 

DateAvg Monthly PriceAvg Prive over last 9 Months
Jan-2063.90047097(NA)
Feb-2055.5744(NA)
Mar-2032.20683871(NA)
Apr-2019.5141(NA)
May-2028.78334194(NA)
Jun-2040.25451333(NA)
Jul-2043.31926452(NA)
Aug-2044.56663871(NA)
Sep-2040.84572667(NA)
Oct-2040.2087806540.99614387
Nov-2042.4403438.36373384
Dec-2050.0143354838.77139445
Jan-2154.4711677438.215388
Feb-2162.384840.4418209
Mar-2165.8393548444.7288909
Apr-2164.3384333348.43449219
May-2168.5550645250.84288419

 

Output should be as follows (as you can see April 2021 has the same values for each day which alligns with the value above in orange)

 

DatePriceAverage Price over last 9 months
1 Apr 202162.187648.43449219
2 Apr 202162.187648.43449219
3 Apr 202162.187648.43449219
4 Apr 202162.187648.43449219
5 Apr 202162.187648.43449219

 

I've been trying many ways of doing this without success. Unsure if it requires a calculated column or if a measure can do this. In excel it is straightforward as there are functions such as offset with the height component but in PowerBI it seems to be more challenging. Any hlep would be greatly appreciated!

 

2 REPLIES 2
amitchandak
Super User
Super User

@kman5554 , Assume you already have a measure monthly price

 

monthly price = Average(Table[Price]) //If price is not a measure

 

with help from date table

 

12 Month Avg = CALCULATE(AverageX(Values('Date'[MONTH Year]),[monthly price])
,DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

 

You can use Numeric Parameter to make 12 dynamic

Example here - https://youtu.be/cN8AO3_vmlY?t=26514

 

You can also use window function

https://youtu.be/cN8AO3_vmlY?t=33360

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks for the help Amitchandak.

 

The measure you provided only works against monthly filtering. If I bring the measure against a daily date context the numbers are variable day to day.

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.