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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.