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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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