cancel
Showing results for
Did you mean:

## DISTINCTCOUNT with filters

Hi,

I'm trying to get a DISTINCTCOUNT after I filtered a table. In the table below, I'm only interested in the records where Answer = Yes. Then, I want to count the distinct clients.

The number of distinct clients should work in any filter context, i. e.:

Overall: 2 clients (A and C)

By year:  2015: 1; 2016: 1; 2017: 1

By city: New York: 1, Moscow: 1

I tried the following code, but it's not considering the filter context. Instead, I always get the total number of distinct clients, no matter the filter context:

CALCULATE (
DISTINCTCOUNT ( Table[Client] ),
))

I'd really appreciate some help here 🙂

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hey @PhotoBiker,

I tried your code and it worked for me. I got a "Clients who Answered Yes" of 1 for all of the specific filters, and 2 if no filters were selected. Did you create a measure or a calculated column? A measure should produce the proper output while a calculated column would behave the way you are describing.

Thanks,

Parker

7 REPLIES 7
Frequent Visitor

I use just measures and is still doent work.

New count = CALCULATE(DISTINCTCOUNT(Sheet1[name]), FILTER('Calendar', [new] = "new"))
new = IF( [Last 365 days1]-[Last 90 days1]= 0,"New")
Last 90 days1 = CALCULATE(SUM(Sheet1[amount ]),DATESBETWEEN(Sheet1[date],MAX([Date])-90,MAX([Date])))
Last 365 days1 = CALCULATE(SUM(Sheet1[amount ]),DATESBETWEEN(Sheet1[date],MAX([Date])-365,MAX([Date])))

I also combined all in one new statement it still doent work. Hope u can help.
Anonymous
Not applicable

Hey @PhotoBiker,

I tried your code and it worked for me. I got a "Clients who Answered Yes" of 1 for all of the specific filters, and 2 if no filters were selected. Did you create a measure or a calculated column? A measure should produce the proper output while a calculated column would behave the way you are describing.

Thanks,

Parker

Helper I

Hi

Can someone highlight the error in my syntax please?

Stage_2_submitted = calculate(
DISTINCTCOUNT('Weekly Report Template'[Application Stage])
,
FILTER('Weekly Report Template',[Application Stage]="23 Retention Payment - Application Closed"))

Hey @Anonymous,

OMG, you just saved my day 🙂 I'm not sure if it's actually funny or embarrassing...

I created a measure, but my data model is fairly complex and there's quite a number of tables that are not related to each other. When I created my measure, I picked the client from an intellisense suggestion - but I chose an unrelated table, that's why the counts were always the same.

Thank you very much for double checking my code, and for confirming that it actually works! Based on that I reviewed my actual code and spotted the error.

Much appreciated!

Anonymous
Not applicable

@PhotoBiker

Awesome, glad to hear it! I like to create a Measures Table where all of my measures are attached. They can get chaotic pretty quick

Anonymous
Not applicable

Hi.

I have similar situation. Scenario:

Table A:

1. Employee Name-column

Table B:

1. Country

Objective: Count distinct Employee Name by Germany and France- ONLY.

• Below is what I have done.
Measure = calculate(DISTINCTCOUNT('tABLE A'[Employee Name]; FILTER('Table B';'Table B (2)'[Country]="Germany" && Table B (2)'[Country]="France.
• Error: Too many arguments passed to DISTINCTCOUNT function.Maximum argument count for the function is 1.
Can anyone help define the write function?

Hey @Anonymous

Could you try this code?

Measure =

CALCULATE(

DISTINCTCOUNT('tABLE A'[Employee Name]);

FILTER('Table B';'Table B (2)'[Country]="Germany" && 'Table B (2)'[Country]="France")

)

I added an extra ' to Table B (2) and " to France. And also some closing brackets.