+ Reply to Thread
Results 1 to 18 of 18

Two Way Look up

  1. #1
    Forum Contributor
    Join Date
    11-10-2012
    Location
    India
    MS-Off Ver
    Excel 2003 to Excel 2010
    Posts
    235

    Red face Two Way Look up

    Hi,
    Can any one solve this look up query with two conditions please..
    thanks in advance
    Attached Files Attached Files
    Click on (*), if you agree.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Two Way Look up

    in g2
    =INDEX($C$2:$C$2000,MATCH(E4&B2,INDEX($A$2:$A$2000&$B$2:$B$2000,0),0)) format cells as date
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Two Way Look up

    ARRAY formula.

    =INDEX(C2:C19,MATCH(E4&F4,A2:A19&B2:B19,0))
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

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

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  4. #4
    Forum Contributor
    Join Date
    11-10-2012
    Location
    India
    MS-Off Ver
    Excel 2003 to Excel 2010
    Posts
    235

    Re: Two Way Look up

    thanks sir....
    can u pl do it from look up or Vlook up please...

  5. #5
    Valued Forum Contributor
    Join Date
    02-05-2013
    Location
    Jakarta, Indonesia
    MS-Off Ver
    Excel 2013
    Posts
    571

    Re: Two Way Look up

    Add column helper to the left before Person Type, so you have format column like this:
    Column Helper (A)|Person Type(B)|Person Name(C)|Date of Joining(D)

    on "Column Helper" A2 add this code and copy down
    Please Login or Register  to view this content.
    So you can use this vlookup:
    Please Login or Register  to view this content.
    Click (*) if you received helpful response.

    Regards,
    David

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Two Way Look up

    nope thats the way to do it use index/match(unless you use a helper)

  7. #7
    Forum Contributor
    Join Date
    11-10-2012
    Location
    India
    MS-Off Ver
    Excel 2003 to Excel 2010
    Posts
    235

    Re: Two Way Look up

    Thanks can it be done without adding, any new column.

    Quote Originally Posted by SDCh View Post
    Add column helper to the left before Person Type, so you have format column like this:
    Column Helper (A)|Person Type(B)|Person Name(C)|Date of Joining(D)

    on "Column Helper" A2 add this code and copy down
    Please Login or Register  to view this content.
    So you can use this vlookup:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Two Way Look up

    read post #6 and read the vlookup help file
    why not index/match, you probablywont use vlookup again once you know how to use that

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Two Way Look up

    Try this array formula**:

    =INDEX(C2:C19,MATCH(F4,IF(A2:A18=E4,B2:B19),0))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Format as Date
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

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

    Re: Two Way Look up

    If you insist on making things difficult, you can enter this array formula (use CNTRL SHFT ENTER)

    =SUBSTITUTE(VLOOKUP(E4&F4,$A$2:$A$19&$B$2:$B$19:$C$19,2,FALSE), E4,"")+0

    What do you have against INDEX/MATCH?
    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

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Two Way Look up

    Quote Originally Posted by vjharry View Post
    can u pl do it from look up or Vlook up please...
    Here's another way using LOOKUP...

    =LOOKUP(2,1/((A2:A19=E4)*(B2:B19=F4)),C2:C19)

    Format as Date

  12. #12
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Two Way Look up

    =LOOKUP(2,1/(A2:A19=E4)/(B2:B19=F4),C2:C19)

    This also works

  13. #13
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Two Way Look up

    and another
    =SUMPRODUCT((A2:A19=E4)*(B2:B19=F4),C2:C19)

  14. #14
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: Two Way Look up

    Another one for that file: =SUMIFS(C2:C19,A2:A19,E4,B2:B19,F4)
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  15. #15
    Forum Contributor
    Join Date
    11-10-2012
    Location
    India
    MS-Off Ver
    Excel 2003 to Excel 2010
    Posts
    235

    Re: Two Way Look up

    Thanks Tony its done ...
    But could you pl let me know what here "2" refers to?
    and same also want to know for "1/((A2:A19=E4)*(B2:B19=F4))"

    Thanks A LOT

    Quote Originally Posted by Tony Valko View Post
    Here's another way using LOOKUP...

    =LOOKUP(2,1/((A2:A19=E4)*(B2:B19=F4)),C2:C19)

  16. #16
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Two Way Look up

    Let's assume this is the data in the range A2:C5...

    M...X...20
    F...X...30
    M...Z...60
    F...Y...50

    We want to retun the value in C2:C5 that corresponds to F in column A and X in column B.

    Using this formula:

    =LOOKUP(2,1/((A2:A5=E4)*(B2:B5=F4)),C2:C5)

    We get the correct result of 30.

    Here's how it works...

    E4 and F4 are the lookup values:

    E4 = F
    F4 = X

    In this application the LOOKUP function has 3 arguments:

    LOOKUP(lookup_value,lookup_vector,result_vector)

    lookup_value = 2
    lookup_vector = 1/((A2:A5=E4)*(B2:B5=F4))
    result_vector = C2:C5

    We want to find the lookup_value of 2 in the lookup_vector and return the corresponding value from the result_vector.

    The lookup_vector is made up of an array of calculations from this expression:

    1/((A2:A5=E4)*(B2:B5=F4))

    When we break that down we get:

    (A2=E4) * (B2=F4) = FALSE * TRUE = 0
    (A3=E4) * (B3=F4) = TRUE * TRUE = 1
    (A4=E4) * (B4=F4) = FALSE * FALSE = 0
    (A5=E4) * (B5=F4) = TRUE * FALSE = 0

    We then do a division operation on these results:

    1/0 = #DIV/0!
    1/1 = 1
    1/0 = #DIV/0!
    1/0 = #DIV/0!

    So, the lookup_vector is the array:

    {#DIV/0!;1;#DIV/0!;#DIV/0!}

    As I said before, we want to find the lookup_value 2 in the lookup_vector {#DIV/0!;1;#DIV/0!;#DIV/0!}.

    However, as we can clearly see there is no lookup_value of 2 in the lookup_vector.

    In this application, if the lookup_value is greater than every value in the lookup_vector then it will match the last value in the lookup_vector that is less than the lookup_value. The errors will be ignored (unless the lookup_vector contains all errors).

    We know that the calculation of the expression:

    1/((A2:A5=E4)*(B2:B5=F4))

    Will generate an array that contains only 2 possible values, either a 1 or the #DIV/0! error. For that reason we know that the lookup_value of 2 will always be greater than any value in the lookup_vector.

    With a lookup_value of 2 the last value in the lookup_vector that is less than 2 is the 1. So, we return the value from the result_vector that corresponds to the 1 in the lookup_vector:

    #DIV/0!...C2
    1...C3
    #DIV/0!...C4
    #DIV/0!...C5

    C3 = 30

    So:

    =LOOKUP(2,1/((A2:A5=E4)*(B2:B5=F4)),C2:C5)

    =30

    Hopefully, that isn't too confusing!

  17. #17
    Forum Contributor
    Join Date
    11-10-2012
    Location
    India
    MS-Off Ver
    Excel 2003 to Excel 2010
    Posts
    235

    Re: Two Way Look up

    Thanks a Lot

  18. #18
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Two Way Look up

    You're welcome!

+ 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