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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Moving Average Query

Hi i'm new to PowerBI and trying to build my first dashboard.

 

Pulling my hair out with the moving average! I'm just trying to copy a graph I normally do in an excel pivot averaging the totals below (only an example, the datset is larger)  in bars and the 12 month moving average in a line.

 

I've tried the below measures from researching online:

 

Moving x months avg 1 = calculate(average('Scrapped'[Total]),DATESINPERIOD('Scrapped'[Date],LASTDATE('Scrapped'[Date]),-12,MONTH))
 
Moving x months avg 2 = CALCULATE(AVERAGEX('Scrapped','Scrapped'[Total]),DATESINPERIOD('Scrapped'[Date],LASTDATE('Scrapped'[Date]),-12,MONTH))

 

12mma_Scrap_Life1 =
var CurrDate = max('DateTable'[Date])
var PreviousDate = date(year(Currdate),Month(Currdate)-12,day(Currdate))
var Result =
Calculate(
    AVERAGEX('Scrapped','Scrapped'[Total]),
    filter(Scrapped,
    Scrapped[Date]>=PreviousDate && Scrapped[Date]<=CurrDate
    )
)
return
Result

 

where

DateTable = DISTINCT('Scrapped'[Date])
 

As well as the quick measure rolling avearge. No matter what i do the 12 month moving average calculates the same as the month average on the graphs.  Not sure what i'm missing. Can anyone please help?

 

DateTotal
31-Oct-20187642
12-Aug-20186052
17-Nov-201810058
02-Sep-20188596
06-Dec-20183863
16-Feb-20197872
15-May-20186366
13-Jan-20196399
16-Feb-20197272
20-Jan-20193551
03-Feb-20193181
04-Aug-20186638
06-Feb-20198197
01-Jan-20195499
17-Nov-20185442
15-Oct-20185739
25-Nov-20184577
06-Dec-20184181
06-Dec-20187053
16-Feb-20192596
13-Aug-20185918
08-Jan-20196847
14-Oct-20187526
15-Oct-20187739
20-Jan-20197270
28-Nov-20187566
22-Dec-20185519
15-Sep-20182630
24-Jun-20187032
23-Oct-20186888
11-Aug-20184629
12-Aug-20186309
04-Jan-20196898
18-May-20187425
19-Nov-20185065
03-Nov-20187038
30-Dec-20185745
08-May-20184908
16-Feb-20196197
23-Apr-20187981
12-Aug-20186306
15-Jul-20181214
14-Dec-20186530
30-Dec-20182540
14-Oct-20185676
24-Feb-20198688
30-Aug-20188881
15-Oct-20183825
1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can try create measures like DAX below.

 

Period End = LASTDATE('DateTable'[Date])

 

Period Start= FIRSTDATE( DATESINPERIOD('DateTable'[Date], [Period End], -12, MONTH))

 

12mma_Scrap_Life1 = CALCULATE(AVERAGEX('Scrapped', 'Scrapped'[Total]),DATESBETWEEN ( 'DateTable'[Date], [Period Start], [Period End] ))

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

In your DateTable, create Year and Month columns.  To your visual, drag Year and Month from the DateTable.  Try this measure for moving average

=AVERAGEX(DATESBETWEEN('DateTable'[Date],EDATE(MIN('DateTable'[Date]),-11),MAX('DateTable'[Date])),'Scrapped'[Total])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can try create measures like DAX below.

 

Period End = LASTDATE('DateTable'[Date])

 

Period Start= FIRSTDATE( DATESINPERIOD('DateTable'[Date], [Period End], -12, MONTH))

 

12mma_Scrap_Life1 = CALCULATE(AVERAGEX('Scrapped', 'Scrapped'[Total]),DATESBETWEEN ( 'DateTable'[Date], [Period Start], [Period End] ))

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Thank you so much it works a million.

 

I've also managed to get the quick measure 'rolling average' to work.  The moving  average value resulting from the formula you shared is correct, however it does not match the latest rolling average value on my graph....

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.