# Who went to both USA & UK? [Excel Challenge]

Share

How about a fun Excel challenge? I have data in below format in the table named trips

I want to know which employees visited both USA & UK?

How would you solve this problem? Post your solutions in the comments.

### Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

### Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Excel School made me great at work.
5/5

– Brenda

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

### CP05: Interview with MrExcel – Bill Jelen (on his incredible work ethic)

Bill Jelen is one of my most favorite people on earth. That is why I wanted to have him as my first guest when I restarted the podcast. Even though I recorded this few weeks ago, only now I got around to publishing it. Please enjoy the conversation with Bill.

## Related Tips

Learn Excel

Learn Excel

Learn Excel

### Python is in Excel! – Here is a complete getting started guide for you

Financial Modeling

Excel Howtos

### Speed up your Excel Formulas [10 Practical Tips]

Formula Forensics

### 13 Responses to “Who went to both USA & UK? [Excel Challenge]”

1. Matej says:

Filter for USA & UK in col 2, remove col 2, keep duplicates col 1, remove duplicates col 1.

2. BDT says:

Is it cheating to use PY formulas?
```python
focal_locs: list[str] = ["UK", "USA"]
df = df_trips.drop_duplicates().query('Country in @focal_locs')
recs_both = df[df['Employee'].duplicated()]
recs_both['Employee'].sort_values()
```

I started to do an Excel solution, but need to run to a meeting. It wasn't as concise as yours anyway!
```
=LET(
focalLocs,{"USA","UK"},
allEmps, UNIQUE(trips[Employee]),
blnEmpsWentToEither, ISNUMBER(XMATCH(trips[Country],focalLocs)),
recsWentToEither, FILTER(trips,blnEmpsWentToEither),
uniqRecsWentToEither, SORT(UNIQUE(recsWentToEither)),
empsWentToEither, CHOOSECOLS(uniqRecsWentToEither,1),
empsWentToEither
)
```
Just need to return the dups from `empsWentToEither`.

3. Rasmus says:

Power Query solution based on Group By and List.Contains.

let
Source = Excel.CurrentWorkbook(){[Name="trips"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", type text}, {"Country", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Employee"}, {{"Countries", each _, type table [Employee=nullable text, Country=nullable text]}}),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Went to both UK and USA", each if List.Contains([CountriesList], "UK") and List.Contains([CountriesList], "USA") then "Went to both UK and USA" else "Did not go to both UK and USA")
in

4. Ranjith says:

Does this require a formula or power query ? A simple pivot table added to data model will allow a count distinct output. A country filter on US & UK should return the two employees.

• Chandoo says:

Good one 🙂 Of course, formula / pq / dax options will give you flexibility to parameterize the country list. That is all.

5. Giancarlo says:

Hi

=TOCOL(UNIQUE(BYROW(trips,LAMBDA(k,@FILTER(trips[Employee],IF(INDEX(k,,2)="UK",(trips[Employee]=INDEX(k,,1))*(trips[Country]="Usa")))))),3)

6. Daniel H says:

Another one, very elegant in my opinion.

=LET(
e, trips[Employee],
c, trips[Country],
one, UNIQUE(FILTER(e, c = "USA")),
two, UNIQUE(FILTER(e, c = "UK")),
combo, XLOOKUP(one, two, two, ""),
SORT(FILTER(combo, combo ""))
)

7. Daniel H says:

In the last filter, "less than" and "more than" signs are gone.

Same formula, this time not using the missing signs:

=LET(
e, trips[Employee],
c, trips[Country],
one, UNIQUE(FILTER(e, c = "USA")),
two, UNIQUE(FILTER(e, c = "UK")),
combo, XLOOKUP(one, two, two, ""),
SORT(FILTER(combo, NOT(combo = "")))
)

8. Eleuterio says:

I've translated from italian language, maybe some separators need to be changed, but is very short:
=LET(
E, trips[Employee],
UNIQUE(
FILTER(
E,
MMULT(
--(
COUNTIFS(
E, E,
trips[Country], {
"UK",
"USA"
}
) > 0
),
{1;1}
) > 1,
""
)
)
)

9. David N says:

=LET(
usa,UNIQUE(FILTER(trips[Employee],trips[Country]="USA")),
uk,UNIQUE(FILTER(trips[Employee],trips[Country]="UK")),
both,FILTER(usa,ISNUMBER(XMATCH(usa,uk))),
SORT(both)
)

• David N says:

Or...

=LET(
emp,UNIQUE(trips[Employee]),
num,MMULT(SIGN(COUNTIFS(trips[Employee],emp,trips[Country],{"USA","UK"})),{1;1}),
SORT(FILTER(emp,num=2))
)

10. tetonne says:

Hi, could be great to add min Excel version required.

11. Stéphane says:

LET(
UK_USA,TAKE(UNIQUE(FILTER(trips,(trips[Country]="UK")+(trips[Country]="USA"))),,1),
UNIQUE(VSTACK(UNIQUE(UK_USA),UNIQUE(UK_USA,,TRUE)),,TRUE))

### Get FREE Excel & Power-BI Newsletter

One email per week with Excel and Power BI goodness. Join 100,000+ others and get it free.