in this video we have one to three different lookup values but when we find matches for those values we're gonna end up with multiple numbers that we need to bring back and add. Now we'll learn how to do this three different ways, but the easiest way involves the new Office 365 function XLOOKUP. Now, currently, September 13th, XLOOKUP is only in Office 365 Insider, but Microsoft says soon enough it'll be in all of Office 365.
Anytime I'm adding with multiple conditions, the most efficient function in Excel is SUMIFS, but wait a second, these conditions are not all in the records. The state condition is up in the column headers, so we'll start with XLOOKUP. We're going to look up the state, comma, within the column headers, and notice one, two, three different columns. I'm going to hit the F4 key, comma, return array, because lookup array has three columns, return array has to have three columns also. But guess what? As soon as we give XLOOKUP multiple rows, it knows we want to look up the entire column F. For close parenthesis, we're doing the exact match, and that's the default. Now watch what happens when I hit enter: it spills the entire looked up column. Now, that's not what we want. F2, we simply want to use that inside of SUMIFS.
Now, SUMIFS and earlier functions, SUMIF, COUNTIF, and those kinds of functions, are notorious for not being able to handle array operations. Luckily, XLOOKUP and the INDEX function deliver range objects, which SUMIFS, or if you're in COUNTIFS, AVERAGEIFS, all of those, the ranges where the numbers go, can understand as a range object. Comma, and now criteria range one, the entire product column F4 to lock it, comma, criteria one, well, there's the product for this row, comma, criteria range two, entire sales rep column F4, comma, criteria two, there it is, close parentheses, and that formula will work. The beautiful thing is that XLOOKUP, right here, and the next row, it's looking up California, but when it gets down to Washington, it's going to look up a different column. Control-Enter, double-click, and send it down.
Now let's go to the Washington row, F2, click inside SUMIFS, click on some range, and if I hit the F9 key, sure enough, look at that, it looked up the correct column. Escape. Bonus formula number one.
No worries if you don't have XLOOKUP, because guess what? INDEX and MATCH have always been able to look up a column. The trick is, when we're doing two-way lookup, the row number we leave empty or put a zero, and it knows to get all the rows. Then, in the column number, MATCH looks up the correct relative position, and because INDEX delivers a range object, we can just put it right into SUMIFS.
How is this going? Way back in the time machine, before we had SUMIFS with that letter S, when we had to add with multiple conditions, we'd have to do an array operation like this inside of SUMPRODUCT, and then look up the column with INDEX and MATCH.
Now, if you want to learn more about XLOOKUP, I have a great comprehensive introduction to this amazing function, and if you want to see another example of three-way lookup with XLOOKUP, check out this video.
