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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Count the occurrence of the value in 3 different tables

Hi! 
I need to find how many times unique ID occures in table B and C and count how many times this Unique ID appears in table A.
In a card visual I need to display this value. So far I was trying below measure, and couple of different once, but nothhing works. It filters it correctly, but it does not show me the proper value in the Card visual. 

Measure =
var _a = SELECTEDVALUE('table A'[Unique_ID])
var _b = COUNTROWS(
    FILTER('Table B', 'Table B'[Unique_ID] = _a))
var _c = COUNTROWS(
    FILTER('Table C', 'Table Cv'[Unique_ID] = _a))
var _d = _b + _c

RETURN
IF(_d > 0, DISTINCTCOUNT('TableA'[Unique_ID]))
 
Paola92_0-1731932818994.png

Paola92_2-1731932862000.png

 

 

 
1 ACCEPTED SOLUTION
Kedar_Pande
Super User
Super User

@Anonymous 

In a card visual, there is no row context to filter the tables, so SELECTEDVALUE or similar row-based filtering won't work properly.

 

Correct Measure:

Measure =
VAR TableBIDs = DISTINCT('Table B'[Unique_ID])
VAR TableCIDs = DISTINCT('Table C'[Unique_ID])
VAR CombinedIDs = UNION(TableBIDs, TableCIDs)
VAR IDsInA = FILTER(CombinedIDs, NOT(ISBLANK(LOOKUPVALUE('Table A'[Unique_ID], 'Table A'[Unique_ID], [Unique_ID]))))
RETURN
COUNTROWS(IDsInA)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

 

View solution in original post

2 REPLIES 2
Kedar_Pande
Super User
Super User

@Anonymous 

In a card visual, there is no row context to filter the tables, so SELECTEDVALUE or similar row-based filtering won't work properly.

 

Correct Measure:

Measure =
VAR TableBIDs = DISTINCT('Table B'[Unique_ID])
VAR TableCIDs = DISTINCT('Table C'[Unique_ID])
VAR CombinedIDs = UNION(TableBIDs, TableCIDs)
VAR IDsInA = FILTER(CombinedIDs, NOT(ISBLANK(LOOKUPVALUE('Table A'[Unique_ID], 'Table A'[Unique_ID], [Unique_ID]))))
RETURN
COUNTROWS(IDsInA)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

 

Anonymous
Not applicable

Hi Kedar, 
Thank you, that works ! The only thing which I changed is below, as I wanted to only count distinct values from both columns B and C. 
 

VAR CombinedIDs = DISTINCT(UNION(TableBIDs, TableCIDs))  

 

Thank you! 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.