Multiple matches in Excel lookups - KING OF EXCEL

KINGEXCEL.INFO ( KING OF EXCEL ) Welcome KINGEXCEL.INFO - Nothing Is Unable ... About Excel Tricks, Learning VBA Programming, Dedicated Software, Accounting, Living Skills ...

## 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.