+ Reply to Thread
Results 1 to 7 of 7

Array Formulas Giving incorrect value

Hybrid View

  1. #1
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Array Formulas Giving incorrect value

    Was working in this thread

    http://www.excelforum.com/excel-gene...-criteria.html

    and trying to get result without dummy columns. All of my array formulas give a result of 3 when the result should be 5. See attached. Thanks!
    Attached Files Attached Files
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Array Formulas Giving incorrect value

    Is it not the case that VLOOKUP will only return the first found match if there are duplicates?
    That might explain the apparrent discrepancy.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Array Formulas Giving incorrect value

    That's right, VLOOKUP doesn't accept a range as the first argument (or at least it doesn't work the way you might expect it to).....but LOOKUP does so given that the first column of location is sorted ascending you could use this to give 5

    =SUMPRODUCT(--(LOOKUP(E2:E21,Location)=A2:A21))

    There are still possible issues though because LOOKUP can give you a "closest match" so if I changed E7 to "Maine" the formula still gives 5.....
    Last edited by daddylonglegs; 02-28-2011 at 12:21 PM.
    Audere est facere

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Array Formulas Giving incorrect value

    This version would weed out any "false positives" by ensuring that E2:E21 actually appears in the lookup range

    =SUMPRODUCT((LOOKUP(E2:E21,Location)=A2:A21)*(COUNTIF(INDEX(Location,0,1),E2:E21)>0))

    ....one remaining issue could be that any entry in E2:E21 alphabetically before the first value in the lookup range will cause an error (#N/A), e.g. if E2 contains "aardvark" that formula gives an error....so you can avoid that by making it into an array formula, i.e.

    =SUM(IF(ISNA(LOOKUP(E2:E21,Location)),"",IF((LOOKUP(E2:E21,Location)=A2:A21)*(COUNTIF(INDEX(Location,0,1),E2:E21)),1)))

    confirmed with CTRL+SHIFT+ENTER

  5. #5
    Valued Forum Contributor
    Join Date
    10-13-2010
    Location
    Sunderland, England
    MS-Off Ver
    Excel 2007 (Home) / 2003 (Work)
    Posts
    740

    Re: Array Formulas Giving incorrect value

    The discrepancy is that the vlookup is only looking in E2, not E2-E21. So it finds 3 instances of Utah in A:A so returns 3.

    I have no idea what the correct formula is though, but thought that input might help?!

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Array Formulas Giving incorrect value

    Thanks DDL ! I will relay to original OP.

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,721

    Re: Array Formulas Giving incorrect value

    Actually I could make that last one a little simpler, no need for ISNA you can just use the COUNTIF as the test, i.e.

    =SUM(IF(COUNTIF(INDEX(Location,0,1),E2:E21),IF(LOOKUP(E2:E21,Location)=A2:A21,1)))

    confirmed with CTRL+SHIFT+ENTER

    That still relies on the lookup range being sorted ascending

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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