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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
ScottKC
Frequent Visitor

Aggregating conditional distinct counts

hi all

How could I achieve the following in a measure? An aggregate count of distinct Customers who had sales in all Channels (A,B,C)?

 

DateCustomerNameChannelSaleAmount
22/01/2023LisaA$2.00
22/02/2023LisaB$20.00
22/03/2023LisaC$200.00
05/03/2023BartB$5.00
06/03/2023MaggieB$7.00
10/03/2023HomerC$100.00
15/03/2023MaggieA$7.00
22/03/2023BartC$0.25
22/03/2023BartB$8.00
22/03/2023BartB$9.00
22/03/2023MaggieC$17.00
22/03/2023MaggieC$17.00

 

Quite simple to get the distinct count of customers = 4

 

I can also get the distinct count of customers for each Channel:

A = 2 customers (Lisa and Maggie)

B = 3 customers (Lisa, Bart and Maggie)

C = 4 customers (Lisa, Homer, Bart and Maggie)

 

But am struggle to the distinct count of customers who have a record in each channel = 2 (Lisa and Maggie)

 

EDIT:

The desired output would look like this:

 

CustomerNameChannel A flagChannel B flagChannel C flagAll Channels flag
Lisa1111
Bart0110
Maggie1111
Homer0010
TOTALS2342

 

Any suggestions?

 

1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User

I think logic like the following should work

All Channels Count = 
// get the list of customers and count the distinct channels for each customer
var CustChannels =  summarize('Table', 'Table'[CustomerName], "ChannelCount", DISTINCTCOUNT( 'Table'[Channel]))
// get the total distinc channels regardless of the filter context
var distinctChannels =COUNTROWS(DISTINCT(ALL('Table'[Channel])))
// count the customers where the number of channels is the same as to the total distinct channels
return countrows(Filter(CustChannels, [ChannelCount] = distinctChannels))

 

This is giving me the output on the last column

d_gosbell_0-1679876306160.png

 

 

View solution in original post

4 REPLIES 4
ninjaryder1st
New Member

I have a similar challenge:

 

Trying to count unique names (same people repeatedly occur in table rows) in a table based on some other column's categorical status:

 

Homer

Marge

Maggie

Bart
Maggie 

Maggie

Bart

 

They all have a categorical status of "Red, Blue, or Green"  and I wanted to count each employee only once, that hs "red" status.      Can't seem to find the DAX expression for this, or steps to create columns or measures to do this.  

Thanks

d_gosbell
Super User
Super User

I think logic like the following should work

All Channels Count = 
// get the list of customers and count the distinct channels for each customer
var CustChannels =  summarize('Table', 'Table'[CustomerName], "ChannelCount", DISTINCTCOUNT( 'Table'[Channel]))
// get the total distinc channels regardless of the filter context
var distinctChannels =COUNTROWS(DISTINCT(ALL('Table'[Channel])))
// count the customers where the number of channels is the same as to the total distinct channels
return countrows(Filter(CustChannels, [ChannelCount] = distinctChannels))

 

This is giving me the output on the last column

d_gosbell_0-1679876306160.png

 

 

amitchandak
Super User
Super User

@ScottKC , Try measures like

 

M1 = countrows(Values(Table[CustomerName]))

 

M2 = countx(Values([Channel]), if([M1] >=2, [Channel], blank()))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks for the reply. It hasn't quite worked for my scenario (I've edited the OP to reflect desried output)... but I'm now trying to use countx() and values() to see if I can modify my measures to suit.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.