Forum Discussion
COUNTDISTINCT on an Aggregation
- 9 years ago
Hi mrpauld,
Step 1- Removing all filter context from Customer field and Month field
Using Allexcept doesn't mean to remove all filter context from Customer field and Month field. If we want to remove filters from any column but only a few from a table, we can use ALLEXCEPT. In other words, we group the rows based on Customer and Month field, while regardless other field context.
Reference: ALL, ALLEXCEPT and VALUES in DAX
Using ALLEXCEPTED versus ALL and VALUESStep 2- We're layering in an ALLSELECTED on the FILTER function.... why?
Based on my test, if we remove ALLSELECTED here, the measure still works.
Customers (>$0) Measure = CALCULATE ( DISTINCTCOUNT ( 'Table'[Customer Name] ), FILTER ( 'Table' , [Sales Measure] > 0 ) )To get more detailed introduction about AllSelected function, please refer to: Understanding AllSelected
Best regards,
Yuliana Gu
Sales Measure =
CALCULATE (
SUM ( 'Table'[Sales] ),
ALLEXCEPT ( 'Table', 'Table'[Customer Name], 'Table'[Month] )
)
Customers (>$0) Measure =
CALCULATE (
DISTINCTCOUNT ( 'Table'[Customer Name] ),
FILTER ( ALLSELECTED ( 'Table' ), [Sales Measure] > 0 )
)Excellent! Thank you so much. Worked perfectly.
In a nutshell, just for my understanding -- what exactly is going on here?
Step 1- Removing all filter context from Customer field and Month field....
Step 2 - We're layering in an ALLSELECTED on the FILTER function.... why?
I tried to research how this works, but am struggling. Thanks again!