Forum Discussion
Count Distinct Measure at lowest level
Hi!, Im struggling with this measure, Im not getting the result I want, I have this table:
| sale_id | sale_type | person |
| 1 | 1 | a |
| 2 | 1 | b |
| 3 | 2 | c |
| 4 | 2 | x |
| 5 | 2 | y |
| 6 | 2 | z |
| 7 | 3 | a |
I want a measure that calculates the distinct count of person for each sale_type, the result should be like this:
| sale_id | sale_type | person | Distinct_Person_Per_Sale_Type |
| 1 | 1 | a | 2 |
| 2 | 1 | b | 2 |
| 3 | 2 | c | 4 |
| 4 | 2 | x | 4 |
| 5 | 2 | y | 4 |
| 6 | 2 | z | 4 |
| 7 | 3 | a | 1 |
This measure works but only If I not add the sale_id to the table:
Hi shoemaker27
Pleas tryDistinct_Person_Per_Sale_Type = COUNTROWS ( CALCULATETABLE ( VALUES ( 'Table'[person] ), ALL ( 'Table' ), -- can use ALLEXCEPT and include filter safe columns if any VALUES ( 'Table'[sale_type] ) ) )Please try
Distinct_Person_Per_Sale_Type =
COUNTROWS (
CALCULATETABLE (
VALUES ( 'Table'[person] ),
ALLSELECTED ( 'Table' ),
VALUES ( 'Table'[sale_type] )
)
)
7 Replies
- tamerj1Community Champion
Hi shoemaker27
Pleas tryDistinct_Person_Per_Sale_Type = COUNTROWS ( CALCULATETABLE ( VALUES ( 'Table'[person] ), ALL ( 'Table' ), -- can use ALLEXCEPT and include filter safe columns if any VALUES ( 'Table'[sale_type] ) ) ) - shoemaker27Frequent Visitor
excellent!! one more workaround, the person dimension:
person kind a director b manager c manager x manager y director z manager If I put an slicer for "Kind", the count returns the same result, and should be the distinct count of person but for the kind selected, I added "kind" to the allexcept but the numbers dont change!
any workaround for this!
thanks a lot! tamerj1
- tamerj1Community Champion
shoemaker27
Please share some details about your data model- shoemaker27Frequent Visitor
The model is like this: