Welcome to Excel magic trick number 1,174. Hey, if you want to download this workbook 1,174 to 1,176, click on the link below the video. Hey, in this video we have two lookup values, a common situation that doesn't really have a straightforward solution in Excel. Hey, we need to find Oakland in this column and downtown in this column. Find a match and return GG to this cell. Now, in this video, I want to look at four different ways to do it when we're looking up text. And then there's a simple way to do it if we're looking up numbers.
Now, the easiest way is to add a new column here because here, this is something that someone sent in to me. The lookup value has no problem joining two individual items. But if you try to do an array calculation where we're joining these first two columns here into a single column, this argument will not handle that array calculation. Now, most functions do handle array calculations, but VLOOKUP table array, it's one of those arguments that just won't do it.
All right, so let's see the easy way first. You create a join column equals city, that's a single item, and join it to the store name. Two items being joined together. Control enter. Double click and send it down. We have a single column. And now we can come over here and say equals V lookup. Join these two items with the ampersand, shift 7. If I highlight that and hit F9, I can see the join symbol creates a single item and VLOOKUP will have no problem finding it over here as a match. Ctrl Z, comma, our table, the entire table. That's the first column, that'll work just fine. Comma, and the column index 1, 2, 3, 4, so I put a four, comma, zero because they're not sorted, close parenthesis, and gig.
Now, if I change this over here to West, let's try at Seattle. And instantly, we get an error. As soon as we change this to three or one of the stores from Seattle, it works. We could amend this by saying IFERROR. Now, in 2007 and later, we can use IFERROR, and it'll catch any error. If you want to just catch the NA, you can use IFNA. This is only in 2013 and later, comma. And the arguments for both IFNA and IFERROR have just one argument, and you say what do you want to put in the cell if it's an error. You can put double quote, double quote, that's a zero-length text string that will show nothing, or you could put something like a message in here like "no match." If I change this back to Oakland, instantly I get "no match." If I change this to downtown, I get a match. We could also leave it empty, right? If we leave it empty like this, that means the zero-length text string, it'll show nothing. I kind of like the "no match" there.
Now, what if we couldn't add this column? Well, we can use the MATCH function. The MATCH function, not math, MATCH, is a lookup function. And just like we did for VLOOKUP, we join these two items, comma. But watch this. This argument right here, lookup array, has no problem joining columns. Now, this is a function argument array operation. Inside this function argument, we're doing an operation not on single items like we did here, but an array of items. That's in essence the definition of an array calculation. Now let's highlight this and F9 and prove it does the same thing as this column right here. If you know array syntax, curly brackets house the array, semicolons mean go down a row, just like we're going down a row here. Ctrl Z, I come to the end, and zero for exact match.
Now what does MATCH do? MATCH actually is different than VLOOKUP. All it will do is look up the two items and tell the relative position, 1, 2, 3, 4. Now if I hit enter, it gives me a value error because this is a special type of formula called an array formula. Actually it's a special type of array formula because this function can't handle array operations without this special keystroke. So if I do Ctrl+Shift+Enter, now I get the correct answer. That's the relative position. But I did Ctrl+Shift+Enter to tell Excel that this is an array formula, up in the curly brackets. Excel tells me this is an array formula by putting those curly brackets in. Now if you try to type those in, it will not work. If I hit enter, the value error here tells me that I didn't use Ctrl+Shift+Enter and I don't see those curly brackets. So Ctrl+Shift+Enter, I see the curly brackets. It's working fine.
Now that's not what I want at all. I have to put it inside another lookup function, INDEX. The array wants the actual values you want to return, comma, there's the row number, 1, 2, 3, 4, or relative position. I come to the end, I close parenthesis. If I hit enter, I get value error because this formula needs Ctrl+Shift+Enter. GG. It's working fine.
Now, if you don't like Ctrl+Shift+Enter, we could take advantage of the fact that there are some functions that can handle array operations. I'm going to paste this here, and it's actually that calculation right there that's giving us the trouble. And watch this. We're going to put that array calculation into another function. The array argument in INDEX is one of the few functions. LOOKUP, SUM, PRODUCT, and AGGREGATE are the other functions. It's one of the only four functions that can handle array operations without Ctrl+Shift+Enter. Now, this is kind of tricky because watch this. I'm going to come to the end of that array calculation. And I'm going to watch this screen tip really carefully. I'm going to type a comma. And normally I put the row number like we just did a second. But if you leave it empty or put a zero, it'll return all the rows. So if I close this off, that means inside the second INDEX, there is the array that's doing an array calculation that's empty. So now INDEX will return the entire column. And if we actually highlight this and hit F9, you can see it's doing the same thing as the array calculation itself that we saw just a second ago. Unlike that though, this can be entered without Ctrl+Shift+Enter. So all we really did was just slap that array calculation there inside of INDEX and leave the row number empty.
Now, if you really wanted to use VLOOKUP, we could get fancy, but I think that without a doubt, if I was going to do a single cell formula, I would just use that one and use Ctrl+Shift+Enter. If I could add an extra helper column, I definitely use VLOOKUP. By the way, this IFNA or IFERROR, we could wrap those around all of these also. But if you wanted to use VLOOKUP for some reason, we are totally allowed to join these two values. Again, those are single items that have no problem. That argument can handle it. But for this table array, we can use the CHOOSE function. And the CHOOSE function needs an index number. And what we're going to do is skip over the index number and put two values that we're going to, in essence, mash together into a table. Remember, we highlighted that, and this one right now, in the value argument of CHOOSE. If I hit F9, there's that single column. That's one column. Now, I'm going to put a comma, the second column right here. Now, how am I going to mash those together into a single table? Because that's what I need for VLOOKUP. Well, that's where the index number comes in. Notice I have value one, value two. That means two things, and I want to retrieve them simultaneously. So I'm going to do another array calculation here, but it's going to be slightly different. I'm using array syntax. I'm going to say, please, index number, give me the first and second arguments listed. That means value one and value two inside of CHOOSE. And if I put it in curly brackets, it will simultaneously grab both of them. And watch this. If you hit F9, it creates a table that VLOOKUP can understand. Curly brackets house the array. Commas mean go over a column. Semicolons mean go down a row. So look, Seattle 1, Timmy, Seattle 1, Timmy. That is a table inside our formula. And then the semicolon means go down a row. Seattle 2, Phil. Seattle 2, go over a column, Phil. You've got to be kidding me. Now, I wouldn't normally do this. I would just use, like I said, one of these, but there it is. Now that's the table array for VLOOKUP. I come to the end. What do I want? That whole table right there only has two columns, the join and the ad manager. So I want to retrieve column index number two, zero, because this is an exact match. Close parenthesis. Now this will need Ctrl+Shift+Enter. If I hit enter, it gives me an NA. If I use Ctrl+Shift+Enter, it will get the right value. Now, when I change this to Seattle, I didn't add the IFNA or IFERROR to any of these, so I get an error temporarily. Seattle 3. Instantly they are all working. Oakland, I need, not the downtown, but the West. And there's GG.
Now, there's actually still a fifth method. And this fifth method will be the best method if you have a proper data set with field names at the top and you have your criteria listed with the exact same field names. Guess what? There's a DGET function. The D is for database. The GET is go get something. The database you have to have field names at the top and records in rows. The field: 1, 2, 3. That's the third field we want to retrieve something from. So I'm going to put a three. Or you could type out "ad manager" in double quotes. Or you could click on a cell with "ad manager," comma, and the criteria. We simply have to have the field names and the criteria below. It'll find Oakland in the city column, West in the store column, and then retrieve whatever's in column three. So that is definitely the best amongst all of these if you have your criteria set up this way and a proper data set.
Now, those are five methods if we have text values to retrieve. If we have number values to retrieve and there's no duplicates, meaning Seattle 1, Seattle 1, we can simply do SUMIFS. Now, this is kind of weird because SUMIFS is meant to add up lots of items with multiple criteria. So we're going to use it just to look up a single item. So it really won't add, or it will add, but there'll only be one item. Sum range, those are the things we're trying to retrieve, comma, criteria range, that's the city, comma, criteria, that's the particular criteria, criteria range two, the store name, criteria two, downtown, close parenthesis. This will not work if there are duplicates, because it will be adding, not retrieving. But because we have no duplicates together in the first two columns, I can go to any one of these. This is Tacoma, Lindy Street, and there it is.
So in this video we did two lookup values. If we have numbers to retrieve and there are no duplicates, SUMIFS. We saw the great DGET if we have proper data sets and proper criteria areas. We saw the ridiculous but interesting VLOOKUP and CHOOSE with no Ctrl+Shift+Enter. We saw how to take advantage of the array argument in INDEX. The one I like for a single cell is INDEX MATCH, and be sure to do Ctrl+Shift+Enter because we're doing an array operation. Or if simply you want to add a join column, then you can use VLOOKUP. And don't forget there's IFNA or IFERROR to avoid errors. All right, we'll see you next trick.
