fbpx

VLOOKUP multiple matches – trick

Share

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

We all know that VLOOKUP can find first match and return the results. But what if you want to VLOOKUP multiple matches? Use this simple trick instead.

Multiple matches in Excel lookups

The problem is simple as illustrated below. Say you have a bunch of dates & locations. You want to find out corresponding date(s) for a location. If you use either VLOOKUP or INDEX+MATCH, you just get the first date, but you want them all.

In new version of Excel (2019), you can use awesome formulas like FILTER() to do exactly this, but most of us are still stuck in older version of Excel. So how to get all the matches?

The trick – Use TEXTJOIN…

TEXTJOIN is a text combining function available on Excel 365. We can it to solve our multiple matches problem.

Let’s say our data is in a table named plan. We want to lookup the location in cell G7 and return all matching dates.

We can use below TEXTJOIN formula (you must press Ctrl+Shift+Enter) to get result as this is an array formula.

=TEXTJOIN(", ",TRUE, IF(plan[Location]=G7,
TEXT(plan[Date],"dddd dd-mmm"),""))

How this multiple match formula works?

Let’s go from inside out.

  1. IF(plan[Location]=G7 this part checks every location in the plan table and returns a bunch of TRUE or FALSE values. The end result would be an array like this. {FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE; TRUE;TRUE;TRUE; FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE}
  2. TEXT(plan[Date], “dddd dd-mmm”) this part takes all the dates in plan table and converts them to dddd dd-mmm format (ie 18/05/2019 becomes Saturday 18-May). The end result would be another array of dates formatted.
  3. IF(plan[Location]=G7, TEXT(plan[Date],”dddd dd-mmm”),””) this entire IF formula results in either a bunch of formatted dates or blanks, based on whether plan[Location] matches G7 or not. So we get something like this. {“”;””;””;””;””;””;””;””;”Saturday 18-May”;”Sunday 19-May”;”Monday 20-May“;””;””;””;””;””;””;””;””}
  4. TEXTJOIN(“, “,TRUE, IF()) this is the final part of the puzzle. TEXTJOIN takes individual bits of the array in #3 and combines them with delimiter , (comma space) but ignores any blanks (TRUE as second parameter). The final result is one text that goes like – Saturday 18-May, Sunday 19-May, Monday 20-May

Why bother with TEXT(plan[Date], “dddd dd-mmm”)?

If you don’t use TEXT() to convert your dates, you get something like this instead – 43603, 43604, 43605. This is because Excel dates are really just numbers. So when you use them in any formula you just get the underlying number value. This is why TEXT() formula is so helpful.

Related: Top 10 tips for working with Excel date & time values.

Still confused? Multiple Matches in Excel – Trick

Not sure how all of this works? Check out below video to understand this trick in detail. You can also watch this on my YouTube channel.

Download VLOOKUP Multiple Matches workbook

I made an example workbook with this formula technique. Click here to download or see this in action online here.

HELP! I don’t have TEXTJOIN()

As mentioned earlier, TEXTJOIN is available in Excel 365 or 2019 + only. So if you are using an older version of Excel, you should use one of the below techniques to get multiple matches.

And yeah, while you are polishing your lookup saw, why not also read these..

How do you multiple match?

Do you use TEXTJOIN() or something else? Or do you just give up after first match? Please share your lookup tricks in the comments box.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
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

Chandoo is an awesome teacher
5/5

– Jason

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.

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.

5 Responses to “VLOOKUP multiple matches – trick”

  1. Ankarath Rajan Pradeep says:

    Hi Chandoo. I learnt vlookup from you a few years back and had been very happy using it, with all its drawbacks. It always helped, and where it couldn't, like looking to the left, I still managed by manipulating my data.
    But recently I stumbled upon DGET and life has changed since. It handles multiple criteria and fills up all gaps of vlookup. DGET is my new favourite now.

    • Duncan says:

      I agree with you and if you have found DGET() I am sure you have found all of the other Database functions too: I recommend everyone to do what you did and learn what they are and how to make them work.

  2. Katherine Carr says:

    Fabulous tips! For many years, I have been using nested INDEX and MATCH (exact) functions to extract records (often with the conditional IF function) , usually using Named Columns, which I find a preferable method to the VLOOKUP and HLOOKUP functions (where column and row location can be dictated). The named ranges are important to me, so that the formulas are interpretable regarding intent. This new TEXTJOIN function for the recent versions of Excel will be very helpful.

  3. Karthik says:

    Just In Time!
    I was about to write to Microsoft today morning requesting to include "CONCATIFS()" function in next update - to club multiple match entries for given criteria(s).. Never knew this "TextJoin" function.. Thanks a lot..!
    Awesome as always @Chandoo!

    Ps: I started making my living by doing Microsoft Excel Training to corporates, part-time - and base for that gyan is mostly from chandoo.org! Hope u wont ask me any royalty and I refer your website for any queries 🙂 ..

  4. T? ?i?n says:

    So, i can see, it's a simple and effective solution. ???

Leave a Reply