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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MikePowerBI
Helper II
Helper II

Excluding values from distinct count based on another column

Hi there, 

 

I am looking to create a measure that counts the unique values of column "Batch" if the "Severity" column equals BLANK, Minor, or Event while also excluding the value from the count if the "Severity" column equals Major or Critical. For example based on the table below, the measure should equal 4 because it includes batches A, C, D, H, while excluding batches B and G. 

 

MikePowerBI_0-1639697043000.png

I tried using the formula: 

 

= CALCULATE(DISTINCTCOUNT('Test Data'[Batch]), FILTER('Test Data', 'Test Data'[Severity] = "Event" || 'Test Data'[Severity] = "Minor" || 'Test Data'[Severity] = BLANK()), FILTER('Test Data', 'Test Data'[Severity] <> "Major"), FILTER('Test Data', 'Test Data'[Severity] <> "Critical"))
 
but it equals 6, so it does not appear to be excluding batches B and G as I intended. 
 
Any help with this would be greatly appreciated!
1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @MikePowerBI 

 

Try this measure:

Measure =
VAR _A =
    CALCULATETABLE (
        VALUES ( 'Table'[Batch] ),
        FILTER ( 'Table', 'Table'[Severity] IN { "", "Minor", "Event" } )
    )
VAR _B =
    CALCULATETABLE (
        VALUES ( 'Table'[Batch] ),
        FILTER ( 'Table', 'Table'[Severity] IN { "Major", "Critical" } )
    )
VAR _C =
    EXCEPT ( _A, _B )
RETURN
    COUNTROWS ( _C )

 

output:

VahidDM_0-1639699912715.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

2 REPLIES 2
VahidDM
Super User
Super User

Hi @MikePowerBI 

 

Try this measure:

Measure =
VAR _A =
    CALCULATETABLE (
        VALUES ( 'Table'[Batch] ),
        FILTER ( 'Table', 'Table'[Severity] IN { "", "Minor", "Event" } )
    )
VAR _B =
    CALCULATETABLE (
        VALUES ( 'Table'[Batch] ),
        FILTER ( 'Table', 'Table'[Severity] IN { "Major", "Critical" } )
    )
VAR _C =
    EXCEPT ( _A, _B )
RETURN
    COUNTROWS ( _C )

 

output:

VahidDM_0-1639699912715.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Hi VahidDM. This worked great, thank you for your prompt reply!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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