Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
TcT85
Helper III
Helper III

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" from OperatorNgType

 

Here is the table

BarcodeOperatorJudgementOperatorNgType
1678564NgAcceptable
1678564NgSolder Bridge
1678565FalseCall 
1678565NgAcceptable
1678565NgSolder Bridge
1678566FalseCall 
1678566NgAcceptable
1678566NgSolder Bridge
1678570NgAcceptable
1678570NgSolder Bridge
1678571NgAcceptable
1678571NgSolder Bridge
1678572NgAcceptable
1678572NgPin Missing
1678572NgSolder Bridge
1678574NgAcceptable
1678574NgSolder Bridge
1678574FalseCall 
1678574NgAcceptable
1678574NgInsufficient Solder
1678574NgSolder Bridge
1678575NgAcceptable
1678575NgSolder Bridge
1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

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:

vjianbolimsft_0-1670221250926.png

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:

vjianbolimsft_1-1670221901830.png

 

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.

View solution in original post

10 REPLIES 10
mario_enrique
Regular Visitor

un ejemplo:

= CALCULATE(DISTINCTCOUNT('Estado de OT'[Orden]),FILTER( 'Estado de OT','Estado de OT'[Estado De OT]<> "Cerrada"))

DimaMD
Solution Sage
Solution Sage

HI @TcT85 Is this your desired outcome?
Screenshot_14.jpg


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
v-jianboli-msft
Community Support
Community Support

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:

vjianbolimsft_0-1670221250926.png

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:

vjianbolimsft_1-1670221901830.png

 

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.

MahyarTF
Memorable Member
Memorable Member

Hi,

Not sure what you mean ?

But I posted the below code :

DistinctCount =
                --CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]), Sheet48[OperatorJudgement] = "falsecall")
                --CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]), Sheet48[OperatorNgType] = "Acceptable")
                CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]), Sheet48[OperatorJudgement] = "falsecall", Sheet48[OperatorNgType] = "Acceptable")
First Line if for calculating the distinct count of the FalseCall value
First Line if for calculating the distinct count of the Acceptable value
First Line if for calculating the distinct count for the rows that has both value in particular columns
 
Appreciate your kudos and please mark it as a solution if it helps you
Mahyartf

Hi MayharTF,

 

I used this one as well:

Distinctcount = CALCULATE( DISTINCTCOUNT('SPC DATA'[Barcode]), 'SPC DATA'[OperatorJudgement] = "falsecall", 'SPC DATA'[OperatorNgType] = "Acceptable")
 
What happens is that i get no data shown.
 
But if I use these with 1 single filter it works.
--CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]), Sheet48[OperatorJudgement] = "falsecall")
 --CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]), Sheet48[OperatorNgType] = "Acceptable")
 
Im not sure if the blanks in the OperatorNgType mess up the data.

The shown result is True,

Because in your sample data there are not any rows with FalseCall and Acceptable values (I mean together).

MahyarTF_0-1668502985732.png

 

Would you please ask you give your Kudos and select it as a solution if it helps you

Mahyartf

Hmm so I need to replace the empty cells with values?

 

Or is there a way to make the DAX formula to understand this?

Hi @TcT85 ,

You have two choices:

1- fill the empty cells with "Acceptable" value and run the existing DAX code.

2- use the below code for creating the Measure :

DistinctCount = --CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]), Sheet48[OperatorJudgement] = "falsecall")
                --CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]), Sheet48[OperatorNgType] = "Acceptable")
                --CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]), Sheet48[OperatorJudgement] = "falsecall", Sheet48[OperatorNgType] = "Acceptable")
                CALCULATE( DISTINCTCOUNT(Sheet48[Barcode]),
                           and(Sheet48[OperatorJudgement] = "falsecall",
                               or(Sheet48[OperatorNgType] = "Acceptable", ISBLANK(Sheet48[OperatorNgType]) )
                               )
                        )
It means if there is any record that the "OperatorJudgement" column is equal "Falsecall" and the "OperatorNgType" column is equal "Acceptable" or is null, this row is counted.
 
Appreciate your Kudos,
Please mark it as a solution if it helps you.
Mahyartf

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 = CALCULATEDISTINCTCOUNT('SPC DATA'[Barcode]), ('SPC DATA'[OperatorJudgement] = "falsecall") || ('SPC DATA'[OperatorNgType] = "Acceptable"))

Hi paladin21,

 

Understood but I need both to be true, otherwise I will get the wrong count.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.