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
mickbergeron
Frequent Visitor

Distinct count based on multiple criterias (and and/or criterias)

We are trying to do a distinct count based on different criterias.

 

Basically, I have Document IDs and Client IDs. A Document ID can be attached to multiple Client IDs and a Client ID can have mutiple Document IDs.

 

Client ID / Document ID

DEF / 222

DEF / 333

DEF / 444

GHI / 222

GHI / 333

 

In that example, a distinct count of client IDs or Document IDs would give me 2 and 3, respectively. Still, because all Document IDs of GHI are also Document to DEF, my distinct count should be 1.

 

2nd example :

Client ID / Document ID

DEF / 222

DEF / 333

DEF / 444

GHI / 222

GHI / 111

 

In that 2nd example, a distinct count of client IDs or Document IDs would give me 2 and 3, respectively again. Still, because not all Document IDs of GHI are also Document to DEF, my distinct count should be 2.

 

Thank you,

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

The numbers in your 2nd example aren't matching up with my expectation of what you want. I get either 3 or 1. But regardless, what you want is something along the lines of:

 

Measure = 
VAR __table1 = DISTINCT(SELECTCOLUMNS(FILTER(Table1,[Client ID]="DEF"),"__DocID",[Document ID]))
VAR __table2 = DISTINCT(SELECTCOLUMNS(FILTER(Table1,[Client ID]="GHI"),"__DocID",[Document ID]))
RETURN COUNTROWS(EXCEPT(__table1,__table2) + COUNTROWS(EXCEPT(__table2,__table1))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

The numbers in your 2nd example aren't matching up with my expectation of what you want. I get either 3 or 1. But regardless, what you want is something along the lines of:

 

Measure = 
VAR __table1 = DISTINCT(SELECTCOLUMNS(FILTER(Table1,[Client ID]="DEF"),"__DocID",[Document ID]))
VAR __table2 = DISTINCT(SELECTCOLUMNS(FILTER(Table1,[Client ID]="GHI"),"__DocID",[Document ID]))
RETURN COUNTROWS(EXCEPT(__table1,__table2) + COUNTROWS(EXCEPT(__table2,__table1))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.