Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VLOOKUP where the key is not in the first column

"The range where the lookup value is located. Remember that the lookup value should always be in the first column in the range for VLOOKUP to work correctly. For example, if your lookup value is in cell C2 then your range should start with C."

But sometimes I want to be able to do dual-direction lookups. Ie, lookup using a key in column A to get the value in column B AND at the same time, in other formulas, lookup the value in B to get the value in A.

The only way I know is to add a column C which mirrors A, then use AB for the first lookup, and BC for the second lookup. But there has to be some cleaner solution. Is there some way to force VLOOKUP to use a different column other than the first one to find the key value, or is there a different function that would allow the equivalent?

As a side note, I am asking about Excel, but I actually use LibreOffice. Presumably the functions should be identical, but an answer that also works in LibreOffice would be preferable.

like image 503
BrianFreud Avatar asked Jul 28 '16 15:07

BrianFreud


People also ask

Can you do VLOOKUP when lookup value is not in first column?

In order for VLOOKUP to work, the lookup value must be on the left-most column on the table array. If your lookup value is not on the first column of the array, you will see the #N/A error.

Does VLOOKUP search first column?

VLOOKUP also assumes by default that the first column in the table array is sorted alphabetically, and suppose your table is not set up that way, VLOOKUP will return the first closest match in the table, which may not be the data you are looking for.

How do I do a VLOOKUP from another column?

The VLOOKUP function can be combined with other functions such as the Sum, Max, or Average to calculate values in multiple columns. As this is an array formula, to make it work we simply need to press CTRL+SHIFT+ENTER at the end of the formula. A very powerful feature for any serious analyst!

Can VLOOKUP return value from left column?

One of the VLOOKUP function's key limitations is that it can only lookup values to the right. In other words, the column that contains lookup values must sit the the left of the values you want to retrieve with VLOOKUP. There is no way to override this behavior since it is hardwired into the function.


1 Answers

INDEX/MATCH will do it any direction of search.

So for your example of B --> A:

=INDEX(A:A,MATCH(yourCriteria,B:B,0))

The MATCH returns the row number of the match. The third Criterion of 0 is optional. The 0 is the same as FALSE for the forth criterion of VLOOKUP, in that it looks for an exact match.

The default is 1 with the data sorted it will return the match that is less than or equal to the criteria Like VLOOKUP's TRUE.

From that the INDEX finds and returns the correct value.


With the introduction of the Dynamic Array formula XLOOKUP we can use:

=XLOOKUP(yourCriteria,B:B,A:A,"",0)
like image 99
Scott Craner Avatar answered Oct 14 '22 15:10

Scott Craner