fbpx
Search
Close this search box.

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

Share

Facebook
Twitter
LinkedIn

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.

Filter employees that visited both countries

Need sample data & my solution? Click here to download the file.

Want more challenges & home-work problems? See this page.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

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

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

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.

Advanced Pivot Table tricks

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.

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_trips = xl("trips[#All]", headers=True)
    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 Custom" = Table.AddColumn(#"Grouped Rows", "CountriesList", each Table.Column([Countries], "Country")),
    #"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
    #"Added Custom1"

  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.

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

Leave a Reply