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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
vnqtrang
Helper I
Helper I

Distinctcount a column if another column matches one of value in another table's column

Hi, 

 

I have 2 tables as below. I would like to distinctcount the column NAME if CODE_A = CODE_B.

 

TableA

NameCODE_A
JohnE333RF, 1234
KarinR344EF, 7654
AllanY345FT
John1234, E333RF
AnnaE333RF, 1234
AlexY345FT

 

TableB

 

CODE_B
E333RF, 1234
R344EF, 7654
Y345FT
3EFE23
A123ER
B123EF

 

Thank you in advance.

Tg

1 ACCEPTED SOLUTION

I found a solution to filter on all the value in the TableB. 

Thank you for your time

View solution in original post

10 REPLIES 10
Avantika-Thakur
Solution Supplier
Solution Supplier

Hi @vnqtrang ,

Considering the fact that Table B has unique codes from Code_A column of Table A , You can try creating the below measure for returing the distinct count of names in matching cases of codes between Table A and Table B -
Measure = 

IF(SELECTEDVALUE('Table A'[CODE_A]) in VALUES('Table B'[CODE_B]),
CALCULATE(DISTINCTCOUNT('Table A'[Name]),ALLEXCEPT('Table A','Table A'[CODE_A])),0)
 
AvantikaThakur_0-1658493888733.png

 

 
Hope this helps!
Please accept the solution if this answers your query.
Thanks!
Avantika

It returns all the name without filter on the code and the result doesn't take into  acount the Slicer filters.

Which slicer filters are we using in the report?

it's slicer filter of the page, I think the Allexcept which exludes all the filters

I am not sure, if that's the Name field which is there in the page slicer.
If yes then you can try putting the slicer field in the expression of "FILTERS" in Calculate function like I have done for Name field -

Count of Names = IF(SELECTEDVALUE('Table A'[CODE_A]) in VALUES('Table B'[CODE_B]),
CALCULATE(DISTINCTCOUNT('Table A'[Name]),ALLEXCEPT('Table A','Table A'[CODE_A]),FILTERS('Table A'[Name])),0)

it returns always the total of name

Hi @vnqtrang ,

Can you pls share the pbix as it would be easy to understand?

I found a solution to filter on all the value in the TableB. 

Thank you for your time

vnqtrang
Helper I
Helper I

TableB is unique value of tableA[Code_A], The expecting output is all the distinct Names which has the CODE_A same as one of code B

 

In the code_A, the order of the codes sometimes is not the same, I would like to  consider Code_A = Code_B even the order is not same.

Avantika-Thakur
Solution Supplier
Solution Supplier

Hi @vnqtrang ,

How are the tables A & B related to each other and how is the sample output that you are expecting?

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.