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
vickyw
Helper I
Helper I

DISTINCTCOUNT with condition

Hi All,

I am surprised this question hasn't come up more - I found a similar post but it didn't the solution didn't work for my situation.

So, I have a PBI report stuffed with measures that look like this:

 

 

 

 

Total Red Cases = CALCULATE(DISTINCTCOUNT('All Cases'[Case Number]), 'All Cases'[CaseColour] = "Red")

 

 

 

 

The measures always perform a distinct count on the [Case Number] field, where a particular criteria is true i.e., where the [CaseColour] field is 'Red'

But I have just discovered that the CALCULATE function overrides the page slicers, so when the end user filters out all the red cases, I would expect the value in my measure 'Total Red Cases' to go to zero however, it remains unchanged.

Is there anyway to prevent CALCULATE from overriding the page filters? Or is there a different way to write the DAX to get around this? Any help appreciated

1 ACCEPTED SOLUTION
rsbin
Super User
Super User

@vickyw ,

I believe the KeepFilters function will help in this situation:

Total Red Cases = CALCULATE(DISTINCTCOUNT('All Cases'[Case Number]), 
                        KEEPFILTERS('All Cases'[CaseColour] = "Red"))

https://learn.microsoft.com/en-us/dax/keepfilters-function-dax
for a completed explanation.

Hope this is what you are aiming for.

Regards,

View solution in original post

2 REPLIES 2
vickyw
Helper I
Helper I

It absolutely does! Thank you so much!! 😄

rsbin
Super User
Super User

@vickyw ,

I believe the KeepFilters function will help in this situation:

Total Red Cases = CALCULATE(DISTINCTCOUNT('All Cases'[Case Number]), 
                        KEEPFILTERS('All Cases'[CaseColour] = "Red"))

https://learn.microsoft.com/en-us/dax/keepfilters-function-dax
for a completed explanation.

Hope this is what you are aiming for.

Regards,

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.