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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
TcT85
Helper III
Helper III

I need help with Distinct Count with excluding filter

Hi,

 

I have two tables, and I need to find the yield for each type.

The tables are fictional, the real table contains over 25 different names in the Type Column.

I only know how to use with including with filters.

Distinct count = CALCULATE(DISTINCTCOUNT('Defect table'[Serialnr] ), 'Defect table'[Type] = "Defect" )
Yield  = 1-  DIVIDE([Distinct count] ,SUM('Produced Table'[Quantity]))
 
How can i make a similar DAX formula with excluding filter?
I would like to exclude warning from this formula.
 
Defect table   
ProductSerialnrPartType
A0001CornDefect
A0001CornWarning
A0002CarrotWarning
A0002CornDefect
A0002CornDefect
A0002CornScratch
A0003CarrotDefect
A0004CabbageDefect
A0004CabbageWarning
B0006CarrotDefect
B0007CornWarning
B0008CarrotWarning
B0009CornDefect
B0010CarrotDefect
B0011CarrotDefect

 

Produced Table   
ProductQuantityDefectWarningScratch
A4431
B6420

 

This is the result I want.

 

Yield Table 
ProductYield
A0%
B33%
1 ACCEPTED SOLUTION

Hi @TcT85 

I included blank value in my table and now I get the following result

Cookistador_0-1744801415080.png

 

To fix that, I have to add the modify my formula with:

Yield =
VAR TotalProduced =
    SUM('Produced Table'[Quantity])
VAR DistinctDefects =
    CALCULATE(
        DISTINCTCOUNT('Defect table'[Serialnr]),
        FILTER(
            'Defect table',
            'Defect table'[Type] <> "Warning"
            && 'Defect Table'[Type] <> ""
        )
    )
RETURN
    IF(
        TotalProduced > 0,
        1 - DIVIDE(DistinctDefects, TotalProduced),
        BLANK()
    )
Because due to my test, the value was empty and not blank
If it is not working, you have to replace
&& 'Defect Table'[Type] <> ""
By
&& 'Defect Table'[Type] <>BLANK()
 

View solution in original post

9 REPLIES 9
v-achippa
Community Support
Community Support

Hi @TcT85,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @bhanu_gautam@mdaatifraza5556@Cookistador for the prompt response.

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the super user's resolved your issue?
If our super user's response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

Hi @TcT85,

 

We wanted to kindly follow up to check if the solution provided by the super user's resolved your issue?

If our super user's response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

TcT85
Helper III
Helper III

Hi @bhanu_gautam , @mdaatifraza5556  and @mdaatifraza5556 

 

Thanks for the quick response all of your solution works, but I have an issue that even blank cells from Type column are included in the calculation.

 

Can anyone of you help me with a dax formula that also exclude the blanks?

Hi @TcT85 

Include one more filtering part in the filter.

'Defect table'[Type] <> blank()

If this answers your questions, kindly accept it as a solution.

Hi @TcT85 

I included blank value in my table and now I get the following result

Cookistador_0-1744801415080.png

 

To fix that, I have to add the modify my formula with:

Yield =
VAR TotalProduced =
    SUM('Produced Table'[Quantity])
VAR DistinctDefects =
    CALCULATE(
        DISTINCTCOUNT('Defect table'[Serialnr]),
        FILTER(
            'Defect table',
            'Defect table'[Type] <> "Warning"
            && 'Defect Table'[Type] <> ""
        )
    )
RETURN
    IF(
        TotalProduced > 0,
        1 - DIVIDE(DistinctDefects, TotalProduced),
        BLANK()
    )
Because due to my test, the value was empty and not blank
If it is not working, you have to replace
&& 'Defect Table'[Type] <> ""
By
&& 'Defect Table'[Type] <>BLANK()
 

@TcT85 , Try this

 

DAX
DistinctCountExcludingWarningAndBlanks =
CALCULATE(
    DISTINCTCOUNT('Defect table'[Serialnr]),
    'Defect table'[Type] <> "Warning",
    'Defect table'[Type] <> BLANK()
)
 
And then 
DAX
Yield =
1 - DIVIDE(
    [DistinctCountExcludingWarningAndBlanks],
    SUM('Produced Table'[Quantity])
)



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






mdaatifraza5556
Super User
Super User

Hi @TcT85 

Please follow the below steps

1. Create measures using below DAX.

    

Distinct Defect Count (Excl Warning) =
CALCULATE(
    DISTINCTCOUNT('Defect table'[Serialnr]),
    FILTER(
        'Defect table',
        'Defect table'[Type] <> "Warning"
    )
)

2. Create second measures using below DAX.

    
Distinct Defect Count (Excl Warning) =
CALCULATE(
    DISTINCTCOUNT('Defect table'[Serialnr]),
    FILTER(
        'Defect table',
        'Defect table'[Type] <> "Warning"
    )
)
 
 
 
3. Here is result.

Screenshot 2025-04-16 131006.png

 


If this answers your question, kindly accept it as a solution and give kudos.
Cookistador
Super User
Super User

Hi @TcT85 

 

The following measure will return the right result

 

Yield =
VAR TotalProduced =
    SUM('Produced Table'[Quantity])
VAR DistinctDefects =
    CALCULATE(
        DISTINCTCOUNT('Defect table'[Serialnr]),
        FILTER(
            'Defect table',
            'Defect table'[Type] <> "Warning"
        )
    )
RETURN
    IF(
        TotalProduced > 0,
        1 - DIVIDE(DistinctDefects, TotalProduced),
        BLANK()
    )
Cookistador_0-1744788799503.png

 

bhanu_gautam
Super User
Super User

@TcT85 , Create two measures

DAX
DistinctCountExcludingWarning =
CALCULATE(
DISTINCTCOUNT('Defect table'[Serialnr]),
'Defect table'[Type] <> "Warning"
)

 

Yield =
1 - DIVIDE(
[DistinctCountExcludingWarning],
SUM('Produced Table'[Quantity])
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors