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
aslee
Helper I
Helper I

Moving average over non-date values

Hi All,

 

I need to calculate a moving average over time, however the time is set as numerical iterations, not dates. 

 

The average needs to be over the 2 iterations - for example, the current iteration being 5, the calculation needs to take the average cycle time of this iteration and previous iteration 4. Then I also need the average of iteration 4 and previous iteration 3, and so on and so forth moving back in time. I eventually want a line chart tracking this moving average as we move forward in iterations. 

 

Some sample data:

 

 

IterationCycle Timeid
120cc-1
117cc-2
122cc-3
223cc-4
25cc-5
215cc-6
210cc-7
211cc-8
218cc-9
321cc-10
420cc-11
414cc-12
425cc-13
59cc-14
511cc-15
512cc-16
527cc-17
520cc-18

 

 

The resulting chart data should be similar to the below:

 

IterationAvg
517.3
420.0
314.7
2

15.7

 

Can anyone assist? I have tried adapting a previous question of mine HERE but this code won't adapt to when I change sum to average. 

1 ACCEPTED SOLUTION
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @aslee

 

Please try the following calculated measure but change Table4 to the name of your table.

 

Avg = FORMAT(
		CALCULATE(
			AVERAGE('Table4'[Cycle Time]),
			FILTER(ALL('Table4'),
					'Table4'[Iteration]>=MAX(Table4[Iteration])-1
					&& 'Table4'[Iteration]<=MAX('Table4'[Iteration])
			)
			),
			"##.0")

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @aslee

 

Please try the following calculated measure but change Table4 to the name of your table.

 

Avg = FORMAT(
		CALCULATE(
			AVERAGE('Table4'[Cycle Time]),
			FILTER(ALL('Table4'),
					'Table4'[Iteration]>=MAX(Table4[Iteration])-1
					&& 'Table4'[Iteration]<=MAX('Table4'[Iteration])
			)
			),
			"##.0")

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thank you @Phil_Seamark! This has worked and looks great in a table - but for some reason I get this error when I go to put it in a line chart

 

Capture.JPG

My x-axis is Iteration, which is set to numerical integer format.

 

Anyone have any ideas what this means? 

@Phil_Seamark

 

Nevermind - worked it out! I took out the formatting section and it fixed it.

 

Thanks again! 

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.