Is there a way with the LOOKUP command to compare numbers?

Is there a way with the LOOKUP command, more specifically the search-for part, to compare numbers and then display the column with the highest number? For example, in my document I have a column with names and then some columns with numbers, the last column has the total of the previous numbers. In a different table I want to display the name of the person with the highest total. Can I do this with the LOOKUP command, or is there a better command?

OS X El Capitan (10.11.6)

Posted on Feb 14, 2017 10:13 AM

Reply
11 replies

Feb 14, 2017 11:45 AM in response to Beuhlig

You could do something like this:


User uploaded file


=INDEX(Table 1::A,MATCH(MAX(Table 1::D),Table 1::D))


INDEX MATCH is a commonly used method to do lookups. It's typically more flexible than LOOKUP, VLOOKUP, and HLOOKUP.


Here:


MAX(Table 1::D) finds the largest value in the 'Sum' column (column D)


MATCH(MAX(Table 1::D),Table 1::D) finds the row number containing that largest value


That row number is then fed to INDEX, which looks up the correspending value in column A.


SG

Feb 14, 2017 3:56 PM in response to Beuhlig

Hi Beuhlig,


Glad the example helped, and thanks for the green tick!


My advice is to avoid LOOKUP. It seems so straightforward but it's a ancient function from the dawn of spreadsheets that has superior modern equivalents in VLOOKUP, HLOOKUP and, especially, INDEX MATCH.


One of the problems with LOOKUP is that it is not explicit about the type of match. So you can end up with a "match" when you don't really want one, or you need a different type of match.


Here's a simple illustration:


User uploaded file



LOOKUP will return a match even if you don't want a value returned when there is no exact match! And LOOKUP always matches on the largest value less than or equal to the lookup value, even if you don't want that. It gives you no warning and you have no choice.


The MATCH in INDEX MATCH, on the other hand, makes available a third parameter (0,1, and -1) that allows you to be more explicit. With 0 you can specify that you really do want an exact match, and want to be alerted if there is no exact match. With 1 you can specify that you want a match on the largest value less than equal to your lookup value (what LOOKUP always does). With -1 you can specify you want a match on the smallest value greater than or equal to your lookup value. That can be handy if you want the "first" match in a column, here the A. (LOOKUP will only give you the "last," the B.)


VLOOKUP (and HLOOKUP) give you similar control to INDEX MATCH but require your columns (or rows) to be in a specific order, which is often inconvenient.


So if you can gain a basic understanding of INDEX MATCH you will find your spreadsheet life simpler and less confusing in the end, even if at first glance the combination seems more complicated than the other lookup methods.


SG


P.S. The formulas pasted below in case you want to play with them:


Formula Used

Type of match

LOOKUP(A2,Table 1::B,Table 1::A)

inexact - find largest value

LOOKUP(A2,Table 1::B,Table 1::A)

inexact - find largest value

INDEX(Table 1::A,MATCH(A3,Table 1::B,1))

inexact - find largest value

INDEX(Table 1::A,MATCH(A4,Table 1::B,-1))

inexact - find smallest value

INDEX(Table 1::A,MATCH(A5,Table 1::B,0))

exact - find value --> error

INDEX(Table 1::A,MATCH(A6,Table 1::B,0))

exact - find value

INDEX(Table 1::A,MATCH(A8,Table 1::B,-1))

inexact - find smallest value

INDEX(Table 1::A,MATCH(A9,Table 1::B,1))

inexact - find largest value

Feb 14, 2017 5:43 PM in response to SGIII

All good points, and generally useful in choosing which function to use.


Irrelevant in this specific case, as the value being searched ( MAX(D) ) is guaranteed to exist in the column. Either of LOOKUP or MATCH (set to large, or small or exact match) will find the value that exactly matches the value they are searching for.


One situation where both MATCH and LOOKUP will fail though, is in cases where there is more than one instance of the search value to be found.


Both MATCH and LOOKUP will find only the FIRST occurrence of an exact match or the FIRST occurrence of the 'close match' that is the best fit to their definition of a 'close match'.

User uploaded file

Both LOOKUP and MATCH grab the first 'best match' they encounter in their search.

LOOKUP starts its search at the bottom of a column, and if it encounters and exact match, accepts that and searches no further.

MATCH, set to 'largest' does exactly the same; starts at the bottom and if it encounters an exact match, accepts it and searches no further.

Set to 'smallest' or to 'exact'. MATCH begins the search at the top of a column, and if it encounters an exact match, accepts that and searches no further.


Regards,

Barry

Feb 15, 2017 9:25 AM in response to SGIII

Hi SG,


I am a big fan of Index/Match and firmly support its use for all lookups. LOOKUP() can remind me of my friend's '48 Ford with the sloppy steering- It can be a real adventure getting where you are going. In that spirit, I offer this solution. It will work properly as long as there is not a larger number in the column than the designated lookup. It will fail if there is a number greater than 10 million but it eliminates the need for MAX().

User uploaded file

quinn

Feb 15, 2017 11:05 AM in response to Beuhlig

For those really interested in best spreadsheet best-practices as regards lookup type functions, check out:


https://support.office.com/en-us/article/LOOKUP-function-446d94af-663b-451d-8251 -369d5e3864cb


The emphasis here is in the original:


User uploaded file


User uploaded file


And this:


https://trumpexcel.com/vlookup-vs-index-match-debate-ends/



The various functions operate the same in major spreadsheet programs, including Excel and Numbers.


SG

Feb 14, 2017 6:10 PM in response to Barry

Hi Barry,


I stand by my advice. Most people should stay away from LOOKUP as it isn't explicit about its behavior. It's a legacy function that long ago was supplanted by better modern alternatives for the reasons I illustrated above. Of the modern alternatives INDEX MATCH combination is the most flexible and gives the user the most control. It can do anything the other functions can do and some things they can't do. If it seems just too complicated (it really isn't complicated, but the function names can seem intimidating at first) then use VLOOKUP or HLOOKUP and rejigger column or row order as needed.


SG

Feb 15, 2017 10:18 AM in response to t quinn

Hi quinn,


That reminds me of solutions I used to see in the old days in Excel (before many of the more modern formulas), with those strange-looking large constants hard-coded right into formulas!


I suspect the logic of the INDEX MATCH with MAX thrown in is tad more explicit. And thus a little easier for other people to follow!


SG

Feb 15, 2017 8:45 PM in response to SGIII

In the early days of Numbers on my iPod it could really struggle. I was looking for the slightest speed increases and felt that INDEX/MATCH helped a bit. That's when I started using it nearly exclusively. It is such a feature rich combo. I do find it a thrill using LOOKUP() when I want to find a value in a range i.e. if >3 then x, if >3 and <5 then y, if >5 then z.


quinn

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Is there a way with the LOOKUP command to compare numbers?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.