# AVERAGEX using CALCULATE or FILTER, or ALL and ALLEXCEPT.



## jsnow123 (Mar 18, 2015)

Firstly, I apologise - I am new to Powerpivot and have tried for a couple of hours to wrap my head around this DAX problem and I cannot afford to waste any more time getting gradually more and more confused.  I desperately want somebody to give me a leg-up.

In excel. I am presenting a tables containing data A, B, C... X, Y in a table with slicers on "Type" and "Period".  In the same data I am trying to create a permanent measure average of 123, for all the periods selected, without "123" selected in a slicer.

I've got as far this, but cannot figure out how to Average123 across the periods selected, so I'm getting the average across all periods.Av123:=AVERAGEX(FILTER(ALL(MyTable),[Type]="123"),[Value])​


TypeValuePeriodA0.11B1011231001C0.12D1021231002X0.13Y1031231003

<tbody>

</tbody>


A quick solution to this would be great, then I can trace it back to try to understand how it all works.  I am now just too confused to understand what a FILTER, CALCULATE, AVERAGEX, measures, tables 

Many thanks


----------



## theBardd (Mar 18, 2015)

Try This


```
CALCULATE( AVERAGEX ( FILTER( MyTable, MyTable[Type] = "123" ), [Sum of Values] ) )
```


----------



## jsnow123 (Mar 18, 2015)

thanks for your response, but I'm afraid that doesn't work.  (note, [Sum of Values] was used in place of [Sum of Value])

Av123:=CALCULATE(AVERAGEX(FILTER(MyTable,MyTable[Type]="123"),[Sum of Value]))

1) it doesn't compute a value for Av123 unless the slicer "123" is selected
2) when "123" is selected by slicer, it doesn't compute the total average per period. I have forgot to mention, that each"Period" has multiple rows (Times, below).



Period123Av123(DESIRED Av123)200:00:006.516.516.5700:00:306.576.576.5700:01:006.606.606.5700:01:306.596.596.57300:00:008.388.388.4700:00:308.498.498.4700:01:008.498.498.4700:01:308.518.518.47

<tbody>

</tbody>


----------



## theBardd (Mar 18, 2015)

Is this what you mean


```
=CALCULATE(
    AVERAGEX ( 
        FILTER( MyTable, MyTable[Type] = "123" ), 
        [Sum of Value] ) , 
        ALL( MyTable[Type]
       )
)
```


----------



## jsnow123 (Mar 18, 2015)

Almost... that now gives an average irrespective of whether "123" is selected by the slicer, but has doesn't provide an average for all Times in the Period... 

Am I fundamentally doing something wrong? Am I explaining it correctly?



Period123Av123410.1410.1400:00:0010.0110.0100:00:3010.1310.1300:01:0010.2010.2000:01:3010.2110.21510.3310.3300:00:0010.3210.3200:00:3010.3410.3400:01:0010.3310.3300:01:3010.3310.33

<colgroup><col><col><col></colgroup><tbody>

</tbody>

<colgroup><col><col><col span="2"><col></colgroup><tbody>

</tbody>


----------



## theBardd (Mar 18, 2015)

Let me try and understand this.

If 123 is selected in the slicer, you want the average of 123 within that period in each row?

If 123 is not selected in the slicer, what do you want to see?

Can you also show some actual data, not just the ave123 or whatever, the actual columns and values including non-123 values, that you have.


----------



## jsnow123 (Mar 18, 2015)

Thanks for sticking in there.  Let me try and explain it properly.

I'm using slicers to effectively jump between different periods (of time) and present different types of measurement data across the period.  I have slicers to also look at different types of data during these periods, but I want to manipulate different types of data differently: e.g. Value, Max(Value), Average(Value).  I used the "123" notation to highlight one manipulation option.

I want to use DAX to create a measure of Average Value of Type "123" <type="123">during the sliced period. <time=sliced period="">

Eventually, I don't actually want to see (slice) data type "123": I want to pass it on to another calculation. I'm selecting the slicer "123" to verify the calculation of Average123.

I can post attach a spreadsheet showing real data, in approx 12 hours from now.

I really appreciate your help.  I hope it will further my understanding of DAX...</time=sliced></type="123">


----------

