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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
baneworth
Helper III
Helper III

Count related table (same ID occurring both tables)

Dear All,

 

i was checking for same issues, since related table questions came up a lot but couldnt find something applicable to mine.

So if you could take a look, that would be very helpful!

 

I have 2 tables with Product ID's.

One is coming from SAP auto created (Main Table) and the other one is manually selected ID's by program which are exempted (based on the auto created ID's).

 

My issue now is, how do i create the DAX to only count ID's from 1st table if they are not matching ID's from 2nd.

 

Best regards

Matthias

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @baneworth 

 

It is better to provide some sample data in a format which people can copy, you have distinct values in ID column in both tables? When you said matching, is there a rule or simple they are the same? You only need to count how many IDs, distinct count? In general, you can do something like this

TEST = 
VAR T1= ADDCOLUMNS(VALUES(Table1[ID]),"CHECK",CONTAINS(VALUES(Table2[ID]),Table2[ID],Table1[ID]))
RETURN
COUNTROWS(FILTER(T1,[CHECK]=FALSE()))

View solution in original post

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @baneworth ,

 

Based on your description, do you want to count the mismatched ID when the ID in Table 1 do not match the selected ID?

If I understand correctly, please create the following measure:

Measure = CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER(ALL('Table'),NOT('Table'[ID] in VALUES('Table (2)'[ID]))))

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Vera_33
Resident Rockstar
Resident Rockstar

Hi @baneworth 

 

It is better to provide some sample data in a format which people can copy, you have distinct values in ID column in both tables? When you said matching, is there a rule or simple they are the same? You only need to count how many IDs, distinct count? In general, you can do something like this

TEST = 
VAR T1= ADDCOLUMNS(VALUES(Table1[ID]),"CHECK",CONTAINS(VALUES(Table2[ID]),Table2[ID],Table1[ID]))
RETURN
COUNTROWS(FILTER(T1,[CHECK]=FALSE()))

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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