transcript

excelisfun - Excel Magic Trick 1259: Can VLOOKUP Lookup Duplicates? Yes! Helper Column or Array Formula?

Thumbnail of the video “excelisfun - Excel Magic Trick 1259: Can VLOOKUP Lookup Duplicates? Yes! Helper Column or Array Formula?”
Download Markdown
Community upload. AI output has not been independently verified.

Welcome to Excel Magic Trick number 1,259. Hey, if you want to download this workbook, Excel Magic Trick 1,258 to 1,259, and follow along, click on the link below the video.

Oh, here is a common problem with VLOOKUP. We are trying to look up the different server names from this data set, but each server has a different event. But look at what VLOOKUP does: it looked up for Event 1 and Event 2, and it only looked up the first one. Then when we got to the next server, there are three instances with three events, but what did it do? It looked up this, and it looks like it's only returning the first one.

Well, that's how VLOOKUP is programmed. When you're doing an range lookup of exact match with a FALSE or a zero, it is programmed to only take the first one when it sees duplicates. So what is the solution? Clearly, server name and event together create a unique identifier. So one of the ways to solve this is to create a helper column and simply take server name and join it using the ampersand, Shift+7, to event. Now we no longer are going to have duplicates in our first column. When I double-click and send this down, I have the server name and event: Event 1, server name and Event 2. Now I can come over here, equals VLOOKUP, and the lookup value. How are we going to join server name and event? Simply click on server name and, right in our lookup value, use the ampersand to join with the event. That way, right here in our lookup value, if I click on that and hit F9, you can see, boom, we have a single item we can look up and try to match in our first column of our VLOOKUP table.

Control+Z, come to the end, comma, and here's our new table: first column all the way to the fourth column, status. I'm going to hit the F4 key. Comma, column index: the fourth column is status, and that has the items we want to go and get and bring back to the cell. So I'm going to put a 4, comma, and either FALSE or zero for exact match, close parentheses, Control+Enter, double-click and send it down. That is amazing. VLOOKUP had no problem, because now it's looking up server name and event, finding a match in that first column.

Occasionally you can't add a helper column to your table and you want a single-cell formula. Well, we're not going to use VLOOKUP for that. By the way, I have a video, Excel Magic Trick 1174, that goes over six different ways to solve this problem, and I show you a bunch of ways there. The main way is to do either helper column and VLOOKUP, or we're going to see the other main way, which doesn't involve VLOOKUP. We're going to use two new lookup functions. The first one is INDEX. INDEX has an array, and those are only the items that you want to go and get and bring back to the cell. I'm going to hit F4, comma, and then all it needs is a row number. Well, notice I only have the options 1, 2, 3, 4, 5, 6, or 7. So somehow, in the row number of INDEX, I need to look up these two items and figure out, without this helper column, what the relative position or which row number it is.

No problem. We're going to use our second lookup function, called MATCH. MATCH can look something up and tell you the relative position of an item in a list, or in our case, the row number. I'm going to do the same trick as I did in VLOOKUP: there's the server name, I join it to the event, comma. Well, wait a second, look up array. If I'm not allowed to have that, I'm just going to create it right in my formula. I have just highlighted the entire server name column, and I'm going to do what's called an array operation. Yes, that's the join symbol. It's the same join symbol we used right here, but here we had one item joined to another item. This is called an array operation because we're not joining just one item to another; that's a whole column, and I'm going to join it to the event column. Now I can click on lookup array and evaluate this with the F9 key to prove to myself that I actually did. I joined each individual item and created a whole new helper column in my formula.

Now, Control+Z. Two things: one, I need to lock this, so I'm going to highlight that colon, because I forgot. I'm going to hit the F4 key, and then right here, F4. Now, this is a special type of operation. It's called an array operation, and we're actually going to have to tell Excel that this is a special type of array operation by using the keystroke Control+Shift+Enter. When we enter the formula, that lookup array requires this special keystroke, or else we will get an error. Now, comma, MATCH has the same exact, so we're going to put zero because we're doing exact match, close parentheses. And boom, there it is: row number. That whole MATCH thing, if I hit F9, delivers a 1. As I copy down, it'll change the relative position. Control+Z, INDEX has what it needs, so I come to the end, close parenthesis. Now we have to use our keystroke Control+Shift+Enter. That's us telling Excel that we made an array calculation. You immediately look up to the formula bar, and you can see those curly brackets. That's Excel telling you it understood that this was an array operation.

Let's just see what happens. If I hit F2 and then Enter, that's the error you'll get. That error says, hey, you forgot to use the special keystroke, Control+Shift+Enter. Now I can double-click and send it down, and boom, a single-cell formula to look up two items without our helper column.

So the two preferred methods are either that single-cell formula or the helper column. But I want to show you one other, third option. I'm going to copy this in edit mode, press Escape, come over here, and paste it with Control+V. When we did this array operation right here in the lookup array, that argument requires Control+Shift+Enter, or it doesn't calculate correctly. But watch this: if we take that whole array operation and simply put it inside a second INDEX. There are five functions in Excel with arguments that can handle array operations without a special keystroke, and the array argument of INDEX is one of them, so it can handle array operations without Control+Shift+Enter. The trick here is we want to get all of the rows simultaneously. So I type a comma, and for row number I leave it empty. By leaving the row number argument empty, it tells INDEX to get all of the rows simultaneously. Now look at this: that means we're simply using INDEX to house that array operation, and it's sitting inside the lookup array, and it will no longer require Control+Shift+Enter. If I press F9, you can see it gives us the same exact simulated helper column inside our formula. Control+Z, but watch: I simply press Control+Enter. I didn't use Control+Shift+Enter. There are no curly brackets, and it works like a charm.

So if you want to use INDEX-MATCH, INDEX, or probably this is the one that I would use if I were doing a single-cell formula. But most of the time, it's certainly fast and easy to just use VLOOKUP with an extra helper column. All right, I'll see you in the next video.