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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Rob_BTG
Frequent Visitor

Count number of times a value appears in a related table, with condition

I keep finding posts that don't quite answer this...

 

I have 2 tables that are conntected by the AppKey column, that is unique to Table 1. 

 

I would like to create a measure that tells me how many times the AppKey in Table 1, appears in Table 2, but only when the Status Code column in Table 2 is not blank.

 

Example:

PBI example 2.JPG

Thanks in advance.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

This solution assumes that your blank columns are actually NULL and not ""  (empty string):

 

# Instances = 
CALCULATE(
	COUNTROWS(Table2)
	,Table2[Status Code] <> BLANK()
)

Table2[Status Code] is actually a blank string, convert it to NULL using Power Query.

 

If you can't do that, you can use this measure:

# Instances = 
CALCULATE(
	COUNTROWS(Table2)
	,Table2[Status Code] <> ""
)

I think you'll get better performance out of your model if it's NULL.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

This solution assumes that your blank columns are actually NULL and not ""  (empty string):

 

# Instances = 
CALCULATE(
	COUNTROWS(Table2)
	,Table2[Status Code] <> BLANK()
)

Table2[Status Code] is actually a blank string, convert it to NULL using Power Query.

 

If you can't do that, you can use this measure:

# Instances = 
CALCULATE(
	COUNTROWS(Table2)
	,Table2[Status Code] <> ""
)

I think you'll get better performance out of your model if it's NULL.

Thanks, that works.  I think you meant to say "Table 1" after COUNTROWS, I used Table 1 and it worked.

 

I may have had the columns backward in my previous attempts to use this.

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.

Top Solution Authors