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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
mshashmi
Frequent Visitor

Moving Average changes when using a Slicer

Hi

 

I have a table and a measure is present to calculate moving average. I have a date slicer present too. Moving average of mine is for previous 3 weeks. So whn any date range is selected, the data of previous weeks is taken as 0 by the measure. This makes first 2 weeks displayed moving average not what it should be.

 

Table

 

Week        Value

1                 12

2                  3

3                  5

4                  7

5                  9

6                  1

 

 

Moving avg for week:

1 - 12/3=4

2 - (12+3)/3=5

3 - (12+3+5)/3=6.67

4 - (3+5+7)/3=5

So on...

 

This is what I required as there is no data before week 1

 

But if I select date slicer from week 3 to week 6

 

I get:

 

Week 3 - 5/3=1.67 whereas I want it to take week 1 and week 2 in consideration too.

I want the average to be 6.67 whereas getting 1.67

 

Can this be achieved and if yes, thn how?

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Moving Average= CALCULATE(
	AVERAGEX(
		lineDataClosed,
		SUM(lineDataClosed[Closed Count])/3
	),
	ALL(lineDataClosed),
	DATESINPERIOD(
		lineDataClosed[Week],
		LASTDATE(lineDataClosed[Week]),
		-21,
		DAY
	)
)

Try this and let me know the result.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Have a look at the DAX statement you have used to calculate your measures.  Dax Statements are context sensitive, meaning that they change their results based on slicers.

 

You might need to make use of an ALL() style function to tell it to consider all of the information.  Its going to be tough to give you a more direct solution because ALL() will avoid every slicer, which you might not want.  So you might need to use ALLEXCEPT().

 

 

@Anonymous

 

Moving Average= CALCULATE(AVERAGEX(lineDataClosed,sum(lineDataClosed[Closed Count])/3),DATESINPERIOD(lineDataClosed[Week],LASTDATE(lineDataClosed[Week]),-21,DAY))

 

This expression is giving me the result as per now. Where do I need to place All() or ALLEXCEPT() to get the desired result?

 

Thanks

Anonymous
Not applicable

Moving Average= CALCULATE(
	AVERAGEX(
		lineDataClosed,
		SUM(lineDataClosed[Closed Count])/3
	),
	ALL(lineDataClosed),
	DATESINPERIOD(
		lineDataClosed[Week],
		LASTDATE(lineDataClosed[Week]),
		-21,
		DAY
	)
)

Try this and let me know the result.

@Anonymous

 

Thanks a lot

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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