Closed Thread
Results 1 to 20 of 20

Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

  1. #1
    Forum Contributor
    Join Date
    01-21-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    227

    Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Hi,

    So I have got that formula by googling that gives the last instance of value of a look up but cant understand its functionality.

    Someone plz explain. Also, other formula for achieving same result if any.

    I have attached my file as well.

    Thanks.
    Attached Files Attached Files
    If I've been of help, plz add reputation.

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Hi and welcome to the forum

    Here is an explanation given by Tony Valko on how "LOOKUP(2,1/" works.

    As an alternative function you can use =INDEX(B2:B10,MATCH(D2,A2:A10,1))

    http://www.pcreview.co.uk/forums/doe...-t3729826.html
    Last edited by AlKey; 10-14-2014 at 11:28 AM.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    For a list of items in A2:A10

    D2: (the value to find)
    E2: =LOOKUP(2,1/(A2:A10=D2),B2:B10))

    The 1/(A2:A10=D2) phrase in that formula calculates an array of #DIV/0!'s and 1's.
    Since we're trying to match 2 (which is larger than any of the calculated numeric values), the LOOKUP function ignores the errors and returns the value associated with the
    LAST numeric item in the array.

    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Hi.

    Thought I may as well through in my two cents' worth!

    The breakdown is as follows:

    =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    The part in red tests each of the values in A2:A10 against the condition of whether they are equal to the value in D2 or not. Hence, it will resolve to a string of TRUE/FALSE returns, i.e.:

    =LOOKUP(2,1/({FALSE;FALSE;FALSE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE}),B2:B10)

    The clever part of this construction is the next bit, which involves taking the reciprocal of each of these Boolean TRUE/FALSE values, and exploiting the fact that, when coerced by any suitable mathematical operation, e.g. division, these Boolean TRUE/FALSE values are converted to their numerical equivalents (TRUE = 1, FALSE = 0), so that:

    =LOOKUP(2,1/({FALSE;FALSE;FALSE;TRUE;TRUE;FALSE;FALSE;FALSE;FALSE}),B2:B10)

    becomes:

    =LOOKUP(2,{#DIV/0!;#DIV/0!;#DIV/0!;1;1;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!},B2:B10)

    since 1/FALSE becomes 1/0, i.e. #DIV/0! and 1/TRUE becomes 1/1, i.e. 1.

    Now, if the lookup_value is NOT found within the lookup_vector, LOOKUP returns the LAST value in that array which is less than the lookup_value. And, since we know that our array consists of only either 1s or #DIV/0!s, all that we have to do is choose a lookup_value which is greater than 1.

    Any such value will do, though obviously there is some logic (and elegance) in choosing 2.

    Since the last non-error value in the above array occurs in position 5 (highlighted):

    =LOOKUP(2,{#DIV/0!;#DIV/0!;#DIV/0!;1;1;#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!},B2:B10)

    Excel is instructed to return the value from the corresponding position in the range B2:B10, i.e. "ras", as you can see below:

    {"sad";"ran";"pri";"dep";"ras";"siy";"fas";"asf";"aji"}

    Hope that helps.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  5. #5
    Forum Contributor
    Join Date
    01-21-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    227

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Thanks all for the replies, esp. Xor, his reply was detailed and in layman's term that I could follow...
    Last edited by sakmsb; 10-14-2014 at 11:54 AM.

  6. #6
    Forum Contributor
    Join Date
    01-21-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    227

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Quote Originally Posted by AlKey View Post
    Hi and welcome to the forum

    Here is an explanation given by Tony Valko on how "LOOKUP(2,1/" works.

    As an alternative function you can use =INDEX(B2:B10,MATCH(D2,A2:A10,1))

    http://www.pcreview.co.uk/forums/doe...-t3729826.html
    thanks for that simple and alternative use on index and match(1), i had always used index and match for reverse lookup and dynamic look ups.. learnt something new...

  7. #7
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    You're welcome and thank you for the feedback!

    Please mark thread as "Solved" if your issue has been resolved. (Selecting Thread Tools -> Mark thread as Solved).

  8. #8
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    I'm very familiar with this process, and if I wasn't, Ron and XOR LX's fine explanation above would settle that. However I believe I found a problem with it, though only tested in XL97 and XL03. If you specify full columns, you get #NUM!, and if you use the 1-isblank or NOT(ISBLANK alternate forms, you get the first, not the last, value in the column.

    Below is a slight variation from the discussion above. This deals with finding the LAST VALUE in a column, rather than the last value matching a certain value.

    (EDIT: Sorry! Earlier I omitted the <>"" in the next two formula )

    lookup(2,1/(A:A<>""),A:A)
    gives #NUM!

    lookup(2,1/(A1:A65535<>""),A1:A65535)
    is fine

    lookup(2,1/(NOT(ISBLANK(A:A),A:A)
    gives the value in A1, that is, the **top** value of the column, whereas I expected the BOTTOM one

    lookup(2,1/(NOT(ISBLANK(A1:A65535),A1:A65535)
    is fine

    lookup(2,1/(NOT(ISBLANK(A1:A10),A1:A10)
    is also fine for a reduced scope

    I've run into problems with full columns in the past - I believe it was with SUMIF - so I sometimes have some gruesome looking arguments of B$1:E$65535 or such.
    Last edited by Oppressed1; 07-23-2017 at 06:37 AM.
    Chip, if you can read this, you're STILL making the world a better place with your immeasurably valuable gifts. Every week, you continue to help me (and untold numbers of others) tremendously. Practically no alternative outlets can match your effectiveness, even over the vast number of topics you demystify and empower usage of. You were, and still are, amazing.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Whole column references don't work in earlier versions of Excel. Don't slow your sheet up with up with B$1:E$65535, ulesss you DO have 65 thousand rows!!!
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  10. #10
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Which versions did you test? BTW, I'm now testing your warning about wasted row checking!

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Anything before and including) 2003.

  12. #12
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    I don't think you're at all right about that, unless you mean in the limited case of this thread's example (and I don't think you tested that either). If you can show me a formula that doesn't work in 2003 and prior, any formula, other than publicized additions such as the new SUMIFS, please share it. I and everyone have used A:A notation since the dark ages. (and SUMIF does in fact respect it)

  13. #13
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    It was sumproduct that I remembered having an issue with. That is not a version issue - it applies to all versions.

    Further, your comment about calculations not respecting the used range appears to be only a [theoretical] issue for UDFs per the following. Excel functions are purportedly optimized with respect to Used Range.

    Excel does document that array formulas did not use entire column references until 2007 though.

    "Whole Column and Row References


    An alternative approach is to use a whole column reference, for example $A:$A. This reference returns all the rows in Column A. Therefore, you can add as much data as you want, and the reference will always include it.

    This solution has both advantages and disadvantages:

    •Many Excel built-in functions (SUM, SUMIF) calculate whole column references efficiently because they automatically recognize the last used row in the column. However, array calculation functions like SUMPRODUCT either cannot handle whole column references or calculate all the cells in the column.


    •User-defined functions do not automatically recognize the last-used row in the column and, therefore, frequently calculate whole column references inefficiently. However, it is easy to program user-defined functions so that they recognize the last-used row.


    •It is difficult to use whole column references when you have multiple tables of data on a single worksheet.


    •Array formulas in versions before Excel 2007 cannot handle whole-column references. In Excel 2007, array formulas can handle whole-column references, but this forces calculation for all the cells in the column, including empty cells. This can be slow to calculate, especially for 1 million rows."
    https://msdn.microsoft.com/en-us/lib...ffice.14).aspx

  14. #14
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    So for those using 2007, that version only, Microsoft states that, for Array formulas (formulas that appear with { } ), both A:A and A$1:A$65000 (moreover A$1000000) are inefficient; a limited stated scope would be preferable for performance. At least that's their claim above.

    (EDIT: you were on to something about limiting range with LOOKUP - the article later says that when you use FALSE (unlike the examples above), you should limit lookup ranges
    "When you must use an exact match lookup, restrict the range of cells to be scanned to a minimum. Use dynamic range names rather than referring to a large number of rows or columns. Sometimes you can pre-calculate a lower-range limit and upper-range limit for the lookup."
    )

    (ONE MORE EDIT: Microsoft does add something about SUMIF: "For functions like SUM, SUMIF, and SUMIFS that handle ranges, the calculation time is proportional to the number of used cells you are summing or counting. Unused cells are not examined, so whole column references are relatively efficient, but it is better to ensure you do not include more used cells than you need. Use tables, or calculate subset ranges or dynamic ranges."

    They're still claiming that only USED cells are considered; but that further limiting of the range could be profitable for performance.
    )
    -----------
    LAST edit! Here is the final word, from the (IMO) world's leading Excel performance expert, Charles Williams. By the way, he co-wrote the article above as well, immensely boosting its credibility.

    https://fastexcel.wordpress.com/2015...a-or-bad-idea/

    "Conclusions

    Excel’s sparse storage methods are efficient and allow for the use of whole column references and contiguous blocks of identical formats. But you need to be careful to minimize both the extent and complexity of the used range.
    ◾Formulas other than array formulas and SUMPRODUCT handle whole column references efficiently.
    ◾But avoid array formula and SUMPRODUCT usage of whole column references.
    ◾Non-array formulas using whole column references are much slower with large used ranges, and even slower with complex used ranges.
    ◾Formulas handle empty cells more efficiently than cells containing data.
    ◾Excel is optimized to handle contiguous blocks of identical formatting efficiently.
    ◾File size is not dependent on the size of the used range.
    ◾File size is largely dependent on the number of cells containing data/formulas and also on the number of non-contiguous formatted cells."
    Last edited by Oppressed1; 07-23-2017 at 09:40 AM.

  15. #15
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Mods I think I'm done on the topic in case it looks like it's yearning for a new thread. I just wanted to caution against using full column reference notation for the original thread contents...at least for the versions that I tested (and I expect it to hold for all versions, unless someone tests and reports that to be incorrect).

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,686

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    The thread will not be closed. It is already marked as solved, but must remain open in case anyone else wishes to add anything later on. Thanks for your understanding.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  17. #17
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Okay. That's what I was aiming to do - add to the solution, adding a caveat, in case it improved the answer. Sorry that it strayed off a bit.

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,686

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    No problem! An interesting diversion.

  19. #19
    Registered User
    Join Date
    05-27-2021
    Location
    Canada
    MS-Off Ver
    365 ProPlus
    Posts
    9

    Question Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    I have a project tracking document on the go where I keep track of small project progress items. I am using
    =LOOKUP(2,1/(1-ISBLANK(4:4)),4:4)
    to place the last entered percentage complete into a column for reference purposes (so no one has to scroll through months of data to see the latest entry)
    I would like to take this percentage complete and multiply it by each tasks estimated hours to help calculate the overall project percentage complete.
    I have been trying various formulas to convert the =lookup formula result into a number I can use to multiply with but am not getting any results.
    I appreciate any input (I'm certainly no excel expert but look forward to learning more)

  20. #20
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Explain =LOOKUP(2,1/(A2:A10=D2),B2:B10)

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 05-19-2017, 12:47 PM
  2. [SOLVED] Performing Case-sensitive Lookup, please explain how this code works
    By Dwexdwex in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-27-2013, 09:30 AM
  3. [SOLVED] Using lookup to reference another cell??? I guess is how i explain that.
    By greenfox74 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-06-2013, 12:34 AM
  4. [SOLVED] Let me see if I can explain this...
    By jsc3489 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 06:05 AM
  5. [SOLVED] Let me see if I can explain this...
    By jsc3489 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1