Get the top result from a countif

Anglais428v2

New Member
Joined
Jun 19, 2020
Messages
27
Office Version
  1. 365
Platform
  1. Windows
I have two tables see below:

Table1:
ToFrom
UKGermany
UKUS
UKGermany
UKFrance
FranceUS
FranceUS
FranceUS
FranceGermany
FranceGermany

Then Table2 (including expected result):
CountryTop 'from'
UKGermany
FranceUS

I need a formula to calculate the results 'Germany' and 'US' in Table2. The formula should look at the Country name in Table 2 (e.g. UK), go to Table1 and search for that country in the 'To' column, then return the 'from' country that has the highest number of results (in this case it would be 'Germany' as it occurs twice when the 'UK' is in the To column. Similarly for 'France' in the To column of Table 2, the result should be the US as it occurs three times in the From column of Table1.

Thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What if there's a tie?
 
Upvote 0
There is unlikely to be a tie, so I'd be happy with a false statement of something like "multiple locations". However, if it is possible to include the tied countries separate by a semi-colon that would be great.
 
Upvote 0
You could try something like:

Excel Formula:
=LET(totals,IF(Table1[To]=[@Country],COUNTIFS(Table1[To],[@Country],Table1[From],Table1[From]),0),TEXTJOIN(",",TRUE,UNIQUE(FILTER(Table1[From],totals=MAX(totals)))))
 
Upvote 0
This is brilliant. Now I just have to break it down to see what is going on.
Many thanks
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top