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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
powerdev
Regular Visitor

IF Distinct

Hi Team,

 

I work in the healthcare industry, and it is important that we obfuscate aggregated patient results if they result in <= 10.

 

So my viz is using a calculated measure of

DISTINCTCOUNT('TableName'[Patient Id])

and it works great and instantaneously.

 

When I try to obfuscate anything 10 and under to a 5 using = 

IF(DISTINCTCOUNT('TableName'[Patient Id] <= 10, 5, DISTINCTCOUNT('TableName'[Patient Id]) 

It doesn't seem to do the distinct count before evaluating. Before I was returning about 20 aggregated records, when adding the code above it turns into several hundred thousand and eventually times out.

 

Any suggestions?

1 ACCEPTED SOLUTION
powerdev
Regular Visitor

Well after fighting this for a while, I noticed that I needed to control with a between statement to avoid zero values and then everything worked fine.

 

Solution:

# of Patients = IF(DISTINCTCOUNT('TableName'[Patient Id]) > 0 && DISTINCTCOUNT('TableName'[Patient Id]) <= 10, 5, DISTINCTCOUNT('TableName'[Patient Id]))

Maybe this can help someone else.

View solution in original post

3 REPLIES 3
powerdev
Regular Visitor

Well after fighting this for a while, I noticed that I needed to control with a between statement to avoid zero values and then everything worked fine.

 

Solution:

# of Patients = IF(DISTINCTCOUNT('TableName'[Patient Id]) > 0 && DISTINCTCOUNT('TableName'[Patient Id]) <= 10, 5, DISTINCTCOUNT('TableName'[Patient Id]))

Maybe this can help someone else.

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @powerdev,

 

Based on my test, calculating Distinctcount nested in an IF function works great. But the result returned by a measure would be affected by context. 

 



 

 

It doesn't seem to do the distinct count before evaluating. Before I was returning about 20 aggregated records, when adding the code above it turns into several hundred thousand and eventually times out.


Could you show me the unexpected result you got now? Also, I need more detailed description about how to simulate a similar report as yours.

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Not sure if this will help, but try precalculating the measure as a variable so that it doesn't have to evaluate twice.

 

Obfuscated Measure = 

VAR Test = 
    DISTINCTCOUNT(TableName[Patient ID])

RETURN

IF(
    Test <= 10,
    5, // Obfuscating
    Test
)

 

Also, this may have just been a typo, but you were missing a few ")"  in your code.

 

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.