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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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
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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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