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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Employee
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
Employee
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.