cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ozlemv Frequent Visitor
Frequent Visitor

DistinctCount with filters

 

Hi everyone,

 

Hoping I could have help on the below issue.

 

I would like to calculate the distinct company ids whose actuals are higher than a fixed value (X)

 

Here's the formula I used:

 

ActivePartnerCount = IFERROR(CALCULATE( DISTINCTCOUNT(vTable1[CompanyID]),filter(vTable1,vTable1[Actuals]>X)),0)

 

If the fixed value(X) is 0, then the formulation is working, but not for other values.

 

Thanks in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft v-huizhn-msft
Microsoft

Re: DistinctCount with filters

Hi @ozlemv,

You use the IFERROR function in your formula, you create a calculated column based on my understanding.

IFERROR(A,B) := IF(ISERROR(A), B, A)

The following sub-formula in your formula is right. When the vTable1[Actuals]>X is ture, it will return a value, if the value of vTable1[Actuals] is 0, it will return 0, so the formula will return 0.

CALCULATE( DISTINCTCOUNT(vTable1[CompanyID]),filter(vTable1,vTable1[Actuals]>X))


As @Mi2n posted, you will get the expected result using the solution given.

If you have any other issue, please describe it clearly and sample data for further analysis.

Best Regards,
Angelia

 

View solution in original post

5 REPLIES 5

Re: DistinctCount with filters

Hi @ozlemv

 

How do you calculate your Fixed value 'X'?

 

Because it is fixed, you do not necessarily need filter function.

If X is fixed:

CALCULATE( DISTINCTCOUNT(vTable1[CompanyID]), vTable1[Actuals]>X) works and is exactly equivalent to

 

CALCULATE( DISTINCTCOUNT(vTable1[CompanyID]), Filter( All( vTable1[Actuals] , vTable1[Actuals]>X) )

Sean Super Contributor
Super Contributor

Re: DistinctCount with filters

Yes I don't see anything wrong with the Measure!

 

However I agree with @Datatouille we don't really know what X is - do you hardcode a number? If so it should work.

 

https://www.sqlbi.com/articles/filter-arguments-in-calculate/

Mi2n Member
Member

Re: DistinctCount with filters

My guess is, you have a calculated value for X instead of a fixed value. Is that right?

ozlemv Frequent Visitor
Frequent Visitor

Re: DistinctCount with filters

Hi all,

 

Thanks for your replies.

 

Actually X is a fixed number. Let's say it's 10000. The formulation is working when X equals to zero, but not with any other number. 

Microsoft v-huizhn-msft
Microsoft

Re: DistinctCount with filters

Hi @ozlemv,

You use the IFERROR function in your formula, you create a calculated column based on my understanding.

IFERROR(A,B) := IF(ISERROR(A), B, A)

The following sub-formula in your formula is right. When the vTable1[Actuals]>X is ture, it will return a value, if the value of vTable1[Actuals] is 0, it will return 0, so the formula will return 0.

CALCULATE( DISTINCTCOUNT(vTable1[CompanyID]),filter(vTable1,vTable1[Actuals]>X))


As @Mi2n posted, you will get the expected result using the solution given.

If you have any other issue, please describe it clearly and sample data for further analysis.

Best Regards,
Angelia

 

View solution in original post

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors