Forum Discussion
Calculate Average based on filtered list
- 8 years ago
Here you are:
M = CALCULATE ( AVERAGE ( Data[Value] ), CALCULATETABLE ( VALUES ( Data[Sales Order] ), Data[Type] = "Customer", Data[Value] >= 10 ) )CALCULATETABLE finds the Sales Orders who are Customer with Value greater than 10, then you use those Sales Order to filter the table.
I know... DAX is an amazing language. When you see the solution you think: "yes, it is obvious", when you need to write it, you struggle in finding the right way. It only takes time and patience, thinking in DAX comes after some time :)
Have fun with DAX!
Alberto Ferrari
http://www.sqlbi.com
HI BILASolution
I want to calculate the average value across all types, but only for the sales orders where the 'Customer' type has a value >10
So if I manually filter in excel, I get the following sales orders that have a value >10
| Type | Sales Order | Value |
| Customer | SO00061705 | 85.2757 |
| Customer | 10464021 | 16.5583 |
| Customer | 112172 | 17.4251 |
| Customer | 10469226 | 17.8755 |
| Customer | 10469232 | 17.8769 |
| Customer | 10466224 | 17.9096 |
| Customer | 10469218 | 17.9111 |
Then if I select these sales orders from the full list, I get
| Type | Sales Order | Value |
| Carrier | SO00061705 | 81.9258 |
| Customer | SO00061705 | 85.2757 |
| Carrier | 10464021 | 14.4451 |
| Customer | 10464021 | 16.5583 |
| Confirmation | 10464021 | 0.0000 |
| Carrier | 112172 | 15.3102 |
| Customer | 112172 | 17.4251 |
| Carrier | 10466224 | 15.7471 |
| Carrier | 10469226 | 15.7633 |
| Customer | 10469226 | 17.8755 |
| Confirmation | 10469226 | 0.0000 |
| Carrier | 10469232 | 15.7645 |
| Customer | 10469232 | 17.8769 |
| Confirmation | 10469232 | 0.0000 |
| Customer | 10466224 | 17.9096 |
| Confirmation | 10466224 | 0.0000 |
| Carrier | 10469218 | 15.7992 |
| Customer | 10469218 | 17.9111 |
| Confirmation | 10469218 | 0.0000 |
from here I want to calculate the average value of each of the types, which I think would be:
Carrier 24.9650
Confirmation 0.0000
Customer 27.2617
Thanks
Hi chris_m,
Try this calculated field formula
=AVERAGEX(FILTER(SUMMARIZE(Data,Data[Sales Order],"ABCD",SUM(Data[Value])),[ABCD]>10),[ABCD])
Hope this helps.
- chris_m8 years ago
Helper I
This one seems to work the same as the previous filter measures - it doesn't select only the sales orders where the customer value is >10
- Ashish_Mathur8 years ago
Super User
Hi chris_m,
It works fine for me. Please see the screenshot. I just slightly modified the formula to also show the value of 0. The revised formula is
=if(ISBLANK(AVERAGEX(FILTER(SUMMARIZE(Data,Data[Sales Order],"ABCD",SUM(Data[Value])),[ABCD]>10),[ABCD])),0,AVERAGEX(FILTER(SUMMARIZE(Data,Data[Sales Order],"ABCD",SUM(Data[Value])),[ABCD]>10),[ABCD]))