cancel
Showing results for
Did you mean:
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

Accepted Solutions
Community Champion

## Re: Moving Average changes when using a Slicer

```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.

4 REPLIES 4
Community Champion

## Re: Moving Average changes when using a Slicer

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().

Frequent Visitor

## Re: Moving Average changes when using a Slicer

@Ross73312

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

Community Champion

## Re: Moving Average changes when using a Slicer

```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.

Frequent Visitor

## Re: Moving Average changes when using a Slicer

@Ross73312

Thanks a lot

Announcements

#### Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

#### MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

#### ‘Better Together’ Integration Forum Launch

We've launched a how-to forum where you can learn about how Power BI integrates with other Power Platform products.

Top Solution Authors
Top Kudoed Authors