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

See when key Fabric features will launch and what’s already live, all in one place and always up to date. Explore the new Fabric roadmap

Reply
Paola92
Frequent Visitor

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

@Paola92 

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

@Paola92 

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

 

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
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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