+ Reply to Thread
Results 1 to 8 of 8

Return value in an array based on 2 ifs

  1. #1
    Registered User
    Join Date
    11-12-2008
    Location
    London
    Posts
    9

    Return value in an array based on 2 ifs

    Hi, I've been searching around, but cannot find what I'm after unfortunately, so thought I would post.

    I need to look through an array of values, find where two values match specific criteria and return a value from a third column.

    For example, take this table:

    [pre]
    A B C D E F
    No Fish Blue 0 F 1
    Yes Fish Red 1 V 2
    Yes Lamb Green 0 B 3
    No Beef Red 1 N 4[/pre]



    When column B is "Fish" and column D is 1, I want to know what is shown in column F.

    The formula I am using (with ctrl+shift+enter) is:

    =IF($B$2:$B$5="Fish",IF($D$2:$D$5=1,$F$2:$F$5,"None"))

    However, this always returns "None", whereas it should return "2".

    What am I doing wrong?! Any help would be greatly appreciated, it's quite frustrating...
    Last edited by Spitinyari; 01-26-2012 at 09:32 AM.

  2. #2
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Return value in an array based on 2 ifs

    You might use
    =IFERROR(LOOKUP(2,1/(($B$2:$B$5="Fish")*($D$2:$D$5=1)),$F$2:$F$5),"None")

    if using Excel 2007 or later.
    Good luck.

  3. #3
    Valued Forum Contributor
    Join Date
    10-06-2008
    Location
    Norway
    MS-Off Ver
    2010
    Posts
    365

    Re: Return value in an array based on 2 ifs

    Or maybe:
    =SUMIFS($F$2:$F$5,$B$2:$B$5,"Fish",$D$2:$D$5,1)

    Or if older Excel:
    =SUM(IF(B2:B5="Fish",IF(D2:D5=1,F2:F5)))
    confirmed eith control/shift/enter

  4. #4
    Registered User
    Join Date
    03-25-2010
    Location
    Negeri Sembilan, Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Return value in an array based on 2 ifs

    Maybe you can try this formula, =IF(AND(B1="Fish",D1=1),F1,"") to check each rows. There should not be one formula to solve this problem because if two rows contain "Fish" and "1", how you want the formula to show values for two F columns value.

  5. #5
    Registered User
    Join Date
    11-12-2008
    Location
    London
    Posts
    9

    Re: Return value in an array based on 2 ifs

    I'm happy to return only the first time the criteria are filled, so estige's formula seems to do the trick, thank you so much! I will have to look up SUMIFS, I haven't used those before.

    Thank you to you all, you've been a great help.

  6. #6
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Return value in an array based on 2 ifs

    That formula adds up all matching rows, rather than returning a specific one, in case that is a problem.

  7. #7
    Registered User
    Join Date
    11-12-2008
    Location
    London
    Posts
    9

    Re: Return value in an array based on 2 ifs

    Ah, I see, good point...

    As I just need to know one of the corresponding values, I will use:

    =IFERROR(LOOKUP(2,1/(($B$2:$B$5="Fish")*($D$2:$D$5=1)),$F$2:$F$5),"None")

    as suggested by OnErrorGoto0, that seems to do the trick.

    Thanks again!
    Last edited by Spitinyari; 01-26-2012 at 09:57 AM.

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Return value in an array based on 2 ifs

    That will return the last matching value - is the order important?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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