+ Reply to Thread
Results 1 to 13 of 13

Can somebody explain how this formula works?

  1. #1
    Registered User
    Join Date
    06-29-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    24

    Can somebody explain how this formula works?

    Hi, I have been given a worksheet with a formula I don't quite understand, and i'd like to know how it works so I can continue to work with the sheet. It is a vlookup formula with an IF statement inside, and the IF statement has a logical test that I do not understand.. It is as follows..

    =VLOOKUP(G56,IF({1,0},G6:G47,$C$6:$C$47),2,0)

    What is the logical test doing? and how does this let the Vlookup formula achieve its goal? Finally, what other used could this have?

    Many thanks -

    O
    Last edited by ocannon1; 04-12-2018 at 07:57 AM.

  2. #2
    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,395

    Re: Can somebody explain how this formula works?

    It's allowing you to do a reverse lookup, which is not natively possible with VLOOKUP, as it works from left to right. This is effectively mimicking an INDEX MATCH lookup. Use the Evaluate Formula feature to step through the formula and see how it calculates.

    The {1,0} is telling Excel that the G range is column 1 of the lookup array and the C range is column 2.

    As we have no idea how it is being used in your scenario, we cannot tell you how ELSE it may be used, but suffice it to say that there is a whole host of uses for VLOOKUP and INDEX MATCH fornulae.
    Last edited by AliGW; 04-12-2018 at 05:57 AM.
    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.

  3. #3
    Registered User
    Join Date
    06-29-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    24

    Re: Can somebody explain how this formula works?

    Ah brilliant, that makes sense that it is a reverse lookup, the lookup value is just a number and the other column is names which it is returning.

    the vlookup is column reference is 2, meaning that the IF function is returning a matrix with two columns. How does it work that the IF function is returning a combination of the value-if-trues and value-if-falses?

  4. #4
    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,395

    Re: Can somebody explain how this formula works?

    Please use the Evaluate Formula feature to step through and see the formula in action - that will make everything clear for you. It's on the Formulas ribbon.

    You can achieve the same with the CHOOSE function:

    =VLOOKUP(G56,CHOOSE({1,2},$G$6:$G$47,$C$6:$C$47),2,0)

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Can somebody explain how this formula works?

    You could simply replace it with
    =INDEX($C$6:$C$47,MATCH(G56,G6:G47,0))
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    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,395

    Re: Can somebody explain how this formula works?

    Yes, indeed, and I alluded to this (but failed to illustrate it) in my second sentence in post #2. I wonder if there is any significant difference in overhead between the three if used on a large dataset?

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Can somebody explain how this formula works?

    I suppose that would depend on your definition of significant. Since the CHOOSE version is creating arrays from the ranges, and since INDEX/MATCH is typically faster than VLOOKUP anyway, in my experience, I'd definitely use INDEX/MATCH- especially as it's more intelligible.

  8. #8
    Registered User
    Join Date
    06-29-2017
    Location
    UK
    MS-Off Ver
    2010
    Posts
    24

    Re: Can somebody explain how this formula works?

    I think I will replace the formulas with the index version. I am going to assume that whoever put it together has googled how to make vlookup go from right to left rather than looking for an alternative.

    I've never used the evaluate formula before, this was very useful in seeing how it is calculated so thank you, I still dont see the logical reasoning behind the use of the IF function, the CHOOSE function makes a lot more sense to me

    thank you both

  9. #9
    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,395

    Re: Can somebody explain how this formula works?

    Yes, I'd do that, too. Glad to have helped!

    I still don't see the logical reasoning behind the use of the IF function ...
    Ditto. To be honest, I hadn't seen it done with IF before, only CHOOSE.
    Last edited by AliGW; 04-12-2018 at 08:08 AM.

  10. #10
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Can somebody explain how this formula works?

    xlnitwit
    INDEX/MATCH is typically faster than VLOOKUP anyway,
    i used to share this illusion
    but
    VLOOKUP is slightly faster (approx. 5%), simpler and uses less memory than a combination of MATCH and INDEX or OFFSET

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Can somebody explain how this formula works?

    That's why I said "in my experience". I've seen articles and tests that have argued each is faster than the other, so I tend to work on the principle that it will vary based on your data setup- I can't honestly see how VLOOKUP referencing a 20 column range could work better than INDEX & MATCH referencing only two of those columns.

  12. #12
    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,395

    Re: Can somebody explain how this formula works?

    I suppose it's not really an issue unless it becomes an issue! We all know that massive datasets can start to crawl, especially if OFFSET and/or array formulae (with INDEX MATCH) are used. As you say, it depends entirely on the dataset and use of the functions in question.

  13. #13
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Can somebody explain how this formula works?

    smth is wrong
    vlookup is a bit slower
    range d!A:Z must be filled with values of worksheet formulas in the first row of ws "x"
    and push GO! on ws "l"
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Can someone explain HOW this formula works?
    By jmrlifesafe in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 02-25-2016, 10:19 AM
  2. [SOLVED] explain my formula and HOW it works (please)
    By galvinpaddy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-15-2015, 05:02 PM
  3. Explain How Specific R1C1 Formula Works
    By chouston in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-03-2013, 02:32 PM
  4. Can someone please explain how this VBA works? fast-vba-fuzzy-scoring-algorithm
    By LightingPop in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-08-2013, 04:00 AM
  5. Replies: 3
    Last Post: 11-08-2012, 09:00 AM
  6. [SOLVED] Can Someone Explain how this formula works?
    By Brightspark in forum Excel General
    Replies: 4
    Last Post: 06-08-2012, 03:40 PM
  7. Explain how vlookup works
    By rajesh.chandra in forum Excel General
    Replies: 2
    Last Post: 07-10-2009, 09:51 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