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
That looks strange, please check the file here:
https://www.dropbox.com/s/r0req2vawl8odip/Chris_M%201.pbix?dl=0
I see the average for all the types:
Have fun with DAX!
Alberto Ferrari
http://www.sqlbi.com
Ah, I think I've figured it out. The example dataset I gave was quite simplified, and in my real dataset I was had grouped some of the 'Types' together, and was referencing the grouped type rather than the base types.
So if I use the base values in the measure, it works! But once the Groups get involved, in the measure or a visual, it stops working.
Thanks Alberto!