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
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])   ) )

 

 

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])   ) )

 

 

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.

Top Solution Authors