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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
olimilo
Continued Contributor
Continued Contributor

COUNTROWS matching value on a column from an unrelated table

The tables cannot be related due to a M:M relationship (the duplicates are apparently valid). We just need to create a calculated column that counts the matches from an unrelated table. TL table is to show the count of the matching TLID rows from the PM table, irrespective of the TLKey or PMKey:

 

Intended output:

TLKey TLID Matches
TLKey_001 TL012230 2
TLKey_002 TL041908 2
TLKey_003 TL012230 2
TLKey_004 TL041908 2

 

PMKey TLID
PMKey_001 TL012230
PMKey_002 TL041908
PMKey_003 TL012230
PMKey_004 TL041908

 

I tried the following calculated column but it is turning an error due to the missing relationship:

 

 

Matches = 
    COUNTROWS(
        FILTER(
            'T2',
            'T2'[TL ID] = 'T1'[TL_ID])
        )
    )

 

 

 

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @olimilo 
Add "calculate" at will fix the issue.

count_repeats = CALCULATE(COUNTROWS(T2),FILTER('T2',T1[test id]='T2'[ID 2]))
Ritaf1983_0-1711433203397.png

pbix with example is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula in the TL table

Matches = calculate(countrows(PM),filter(PM,PM[TLID]=earlier(TL[TLID])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @olimilo 

 

Your solution is great, @Ritaf1983 . Here are my additions.

 

I had no relationship between my two tables and then I used your method to get the correct result.

vxuxinyimsft_0-1711504726808.png

 

vxuxinyimsft_2-1711504957730.png

 

Best Regards,
Yulia Xu

 

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

Ritaf1983
Super User
Super User

Hi @olimilo 
Add "calculate" at will fix the issue.

count_repeats = CALCULATE(COUNTROWS(T2),FILTER('T2',T1[test id]='T2'[ID 2]))
Ritaf1983_0-1711433203397.png

pbix with example is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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