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

Distinct Count If Rows are duplicate in certains conditions

Hi folks,

 

Please, I have a table like this

 

Category1Client
A1
B1
B2
A3
A4
B4

 

Distinct Count of Client

4

 

Distinct Count of Client only if Category1 has different values

2 (because Client 1 ans 4 has A and B values)

 

Using DAX, how can I achieve this??

 

9 REPLIES 9
felipevaz
Helper I
Helper I

Let me reintroduce the question...also include a new dimension here to better explains the context

 

Category1DateClient
A01/01/20201
B02/01/20201
B01/01/20202
A02/01/20203
A01/01/20204
B01/01/20204

 

The distinct count has to change if the dimensions are filtered, like

 

Case 1) Distinct count of Client = 4

Case 2) Distinct count of Client in 01/01/2020 = 3

Case 3) Distinct count of Client that has both A and B category = 2

Case 4) Distinct count of Client in 01/01/2020 that has both A and B category = 1

 

I need to measure the distinct count if Category1 has no filter, if the Client has A and B or if the Client has A OR B value...

 

Can it be done in one measure?? Using diferent dimensions?

 

Sorry my english, it is not thaaat good.

 

Anonymous
Not applicable

It should have work with both filter and unfiltered conditions.

What do you mean by not showing right behaviour?
Thanks,
Pravin

Pravin,

 

The function

 

values=Sumx(Summerize(table,table[Client],"Count",DistinctCount(table[Category1])),if([Count]>1,1,0))

 

is returning 2 if the "Client" has "A" and "B" values at the same time.

 

But this is not the total number of distinct Clients...is 4

 

Category1DateClient
A01/01/20201
B02/01/20201
B01/01/20202
A02/01/20203
A01/01/20204
B01/01/20204

 

The distinct count has to change if the dimensions are filtered, like

 

Case 1) Distinct count of Client = 4

Case 2) Distinct count of Client in 01/01/2020 = 3

Case 3) Distinct count of Client that has both A and B category = 2

Case 4) Distinct count of Client in 01/01/2020 that has both A and B category = 1

 

I need to measure the distinct count if Category1 has no filter, if the Client has A and B or if the Client has A OR B value...

 

Can it be done in one measure?? Using diferent dimensions?

Anonymous
Not applicable

Where are you applying measure?
Is it in card or table itself?

And where are applying filter
Is it in slicer ?

If you are taking date column in slicer and the measures in card..value of measure will change with selected date in slicer.

I hve given two measures one is for distinctcount of clients.
Other one is distinctcount of clients have both a and b.

Both measures value will get change with filteres.

Thanks
Pravin

@felipevaz 

Just reading your replies, are you wanting a measure that behaves differently depending on whether certain filters are applied? That is certainly possible using functions like ISFILTERED.

 

Do you want a measure that:

  1. In certain cases returns regular distinct count
  2. In other cases returns distinct count of clients with multiple Category1 values?

Both my and @Anonymous 's measures posted earlier return option 2.

 

Could you clarify in which cases you want option 1 & option 2?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
Anonymous
Not applicable

Hi @felipevaz 

Distinct Count of Client=DistinctCount(table[Client])

 

 

Distinct Count of Client only if Category1 has different values=Sumx(Summerize(table,table[Client],"Count",DistinctCount(table[Category1])),if([Count]>1,1,0))

 

Drag above measures in seperate card visuals.

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

 

 

Thank you Wattamwar

It works well, but when I need to filter the Category1 the measure does not represent the right behavior. Like, if I select Category1 = A the measure does not distinct count the cases.

May I use booth cases in the same measure?
Distinct count Client by A cases OR
Distinct count Client by B cases OR
Distinct count Client by AB cases OR
Distinct count Client independently
OwenAuger
Super User
Super User

Hi @felipevaz 

Something like this should do what you want:

 

Distinct Count of Client only if Category1 has different values = 
COUNTROWS ( 
    FILTER ( 
        VALUES ( YourTable[Client] ),
        CALCULATE ( DISTINCTCOUNT( YourTable[Category1] ) ) > 1
    )
)

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Thank you Owen

It works well, but when I need to filter the Category1 the measure does not represent the right behavior. Like, if I select Category1 = A the measure does not distinct count the cases.

May I use booth cases in the same measure?
Distinct count Client by A cases OR
Distinct count Client by B cases OR
Distinct count Client by AB cases OR
Distinct count Client independently

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.

Top Solution Authors