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
WonderCoding
Frequent Visitor

count number of entries where one attribute matches a table but another doesn't

Hello,

 

So I have two tables, one with shipping information (departure country and arrival country)

Shipping

idDepartureCountryArrivalCountry
1BRUS
2ITPT
3USIT

 

And another with a list of European countries. 

 

I was able to get the count for the shipping arriving at Europe with a measure that in this example would return 2 for ids 2 and 3

CALCULATE(COUNT(Shipping[ArrivalCountry]),RELATEDTABLE(Europeanlist))
 
Now I want to be able to count the number of entries where they departed from a non-European country and arrived at a European country. In the example above the count would only return 1 for the id 3. The problem is that both the attributes are related to the same table so I would need to use USERELATIONSHIP to change the relation and a NOT(RELATEDTABLE()), but I cant manage to get it to work. Any ideas?
 
Thanks in advance 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@WonderCoding , If Europeanlist is not filtered (in Slicer or filter )

 

Try a measure like 

CALCULATE(COUNT(Shipping[ArrivalCountry]),filter(Shipping, not shipping[DepartureCountry] in values(Europeanlist[Country])  && shipping[ArrivalCountry] in values(Europeanlist[Country])   ) )

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

You could create a measure like

Shipped from non-Europe to Europe =
var euroCountries = ALLNOBLANKROW('European List'[country])
var nonEuroCountries = ALLNOBLANKROW('Non European List'[country])
return CALCULATE( COUNTROWS(Shipping), TREATAS( nonEuroCountries, Shipping[Departure country]),
TREATAS( euroCountries, Shipping[Arrival Country])
)
amitchandak
Super User
Super User

@WonderCoding , If Europeanlist is not filtered (in Slicer or filter )

 

Try a measure like 

CALCULATE(COUNT(Shipping[ArrivalCountry]),filter(Shipping, not shipping[DepartureCountry] in values(Europeanlist[Country])  && shipping[ArrivalCountry] in values(Europeanlist[Country])   ) )

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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
Top Kudoed Authors