DAX Distinct Count Question

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I'm trying to calculate a distinct count of customers and having some difficulty; my table is like this,

CustomerSales TeamCol1Col2Col3
abc123xxxxxx
def456xxxxxx
abc789yyyyyy

<tbody>
</tbody>

So what I am looking for is the distinct count of Sales Team by Customer, but I want the measure to respect any filters applied to Col1, Col2, Col3.

So if I have a PivotTable showing customer abc with no other filters, then it should show 2. But if I have a slicer that is slicing Col1's value of 'yy' out, then it should be just 1.

So far I have:
Code:
=
[SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]CALCULATE[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1]([/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]DISTINCTCOUNT[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1]( [Sales Team] ),[/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]ALLEXCEPT[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1](Sales,Sales[Customer]))[/SIZE]
[SIZE=1][/SIZE]

But this would still return 2 even if I filter out 'yy'.

Is there an easy solution?

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
And to try:

Measure:CountTeam:=DISTINCTCOUNT( [Sales Team] )

In Pivot Table Fields:

Rows: Sales Team
Σ VALUES: CountTeam
FILTERS: Costumer, Col1...
 
Last edited:
Upvote 0
Yes, just a measure with DISTINCTCOUNT ( Sales[Sales Team] ) should be all you need.

Your ALLEXCECPT function call was removing all the column filters on the 'Sales' table except for any filters on the 'Customer' column which is why you were still getting a 2 in your example above. Even though you were slicing 'yy', the ALLEXCEPT turned around and removed the 'yy' column filter.
 
Upvote 0
Sorry I should have stated this originally but I want the measure to work even if I have Sales Team in my Rows, like this:

Rows:
Sales Team
Customer

What I'm really looking for is to look at specific customers within a given sales team, and know whether that customer is also serviced by another sales team, so I think just DISTINCTCOUNT won't let me put Sales Team into the rows like that and still give me the total number of distinct sales team per customer.
 
Last edited:
Upvote 0
You can try
Code:
= CALCULATE ( DISTINCTCOUNT ( Sales[Sales Team] ), ALL ( Sales[Sales Team] ) )
This should only override the filter on Sales Team, keeping any other filters active.

I hope it helps.

*Note: I recommend you check the Rules for DAX Code Formatting from The Italians. There are some key aspects like always including the table name when you are referencing a column and never including it when you reference a measure.
 
Upvote 0

Forum statistics

Threads
1,214,527
Messages
6,120,054
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top