Forum Discussion

TcT85's avatar
TcT85
Helper III
3 years ago
Solved

Distinct count with multiple filters

Hi   I been trying different solutions for this topic but I can't get it to work. I need to distinct count the barcode with 2 filters and that is "FalseCall" from OperatorJudgement and "Acceptable...
  • v-jianboli-msft's avatar
    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")+0

    Output:

    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.