Forum Discussion
Distinct count with multiple filters
- 3 years ago
Hi TcT85 ,
When the DISTINCTCOUNT() function finds no rows to count, it returns a BLANK, otherwise it returns the count of distinct values.
So if you want the both filter to be true and not return blank value, please try:
Distinctcount = CALCULATE( DISTINCTCOUNT('SPC DATA'[Barcode]),'SPC DATA'[OperatorJudgement] = "falsecall", 'SPC DATA'[OperatorNgType] = "Acceptable")+0Output:
If you just want to calculate the barcode with "FalseCall" and "Acceptable" instead of requiring both values on the same line, please try:
Distinctcount2 = VAR _a = SUMMARIZE ( 'SPC DATA', [Barcode], "Flag", IF ( "FalseCall" IN SELECTCOLUMNS ( FILTER ( 'SPC DATA', [Barcode] = 'SPC DATA'[Barcode] ), "OperationJudgement", [OperatorJudgement] ) && "Acceptable" IN SELECTCOLUMNS ( FILTER ( 'SPC DATA', [Barcode] = 'SPC DATA'[Barcode] ), "OperationNgType", [OperatorNgType] ), 1, 0 ) ) RETURN SUMX ( _a, [Flag] )Output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hmm so I need to replace the empty cells with values?
Or is there a way to make the DAX formula to understand this?
It depends on the logic you want it to have. What you have posted acts when both statements are true ("FalseCall" AND "Acceptable"). If you want to show if either of them is true, you should change the code to reflect so like this:
Distinctcount = CALCULATE( DISTINCTCOUNT('SPC DATA'[Barcode]), ('SPC DATA'[OperatorJudgement] = "falsecall") || ('SPC DATA'[OperatorNgType] = "Acceptable"))
- TcT853 years agoHelper III
Hi paladin21,
Understood but I need both to be true, otherwise I will get the wrong count.