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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

DAX Distinct Count

I'm trying to do distinct count at a total level by all columns except for one. For example:

 

My sample data is pasted below:

QuoteCompanyAttr1
1AN
1BN
1CN
2AN
2BN
2CN
2DN
3AY
3DY
3EY

 

If the user groups the data by just Company, I would like the pivot table to look like this:

CompanyCount
A3
B3
C3
D3
E3

I have figured this out by using the following formula = COUNTX(ALL(Data[Quote]),DISTINCTCOUNT([Quote]))

 

However, if the user segments the view by Attr1 field, then I would like the pivot table to look like this:

CompanyNY
A21
B21
C21
D21
E21

This is where I am struggling with. Any help would be appreciated. Please note that there are more than just one Attr(n) field in my full dataset.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@amitchandak I apologize for the mistake. I wanted the output in the second view to look like this.

CompanyNY
A21
B2 
C2 
D11
E 1

 

I think I managed to figure it out. =CALCULATE(DISTINCTCOUNT(Data[Quote]),ALL(Data[Quote],Data[Company]))

Do you agree with this?

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

Please try the following. Also is Attr1 part of the same table or different

 

 

COUNTX(Data[Quote],DISTINCTCOUNT([Quote]))

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

 

Anonymous
Not applicable

@amitchandak Thanks for the suggestion, but as I mentioned in my question. I have figured out the formula for the first view with just company. I'm struggling with the second view. and Yes, Attr1 is in the same table. Thanks for taking the time.

I fail to understand with the given sample data why B is 1 in Y. Can you please provide more info on the second calculation.

Anonymous
Not applicable

@amitchandak I apologize for the mistake. I wanted the output in the second view to look like this.

CompanyNY
A21
B2 
C2 
D11
E 1

 

I think I managed to figure it out. =CALCULATE(DISTINCTCOUNT(Data[Quote]),ALL(Data[Quote],Data[Company]))

Do you agree with this?

In case it is working out. Then it should be fine.

But All on Quote and company will disable filter on those. I hope that is intentional. And you should get the same result without those too; if there is no other filter.

 

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.