+ Reply to Thread
Results 1 to 11 of 11

VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

  1. #1
    Registered User
    Join Date
    12-23-2015
    Location
    Amsterdam
    MS-Off Ver
    latest
    Posts
    11

    VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    Hi All!

    I am struggling with a formula where I think I need an Vlookup & AND/IF statements for, but I am not sure.
    So this is the situation:

    Dataset 1:
    Column A: Title
    Column B: Date
    Column C: Where the Formula should show a Number or UNKNOWN

    Dataset 2:
    Column A: Title
    Column B: Start Date
    Column C: End Date
    Column D: Number

    I want it to work like this: If the title in Dataset 1 matches the title in Dataset 2 AND if the Date from Dataset 1 falls between the start and end date from Dataset 2, I want to show the number (Column D) from dataset 2. If else: show the word 'UNKNOWN'.

    I Added two dummy datasets to show what should happen > Dataset 1.xlsx Dataset 2.xlsx (I Accidently added column E & F in dataset 2, please ignore these columns)

    Please help !

    Thanks.
    Last edited by EndeHerc; 01-05-2016 at 10:59 AM.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,082

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    Try

    =IFERROR(VLOOKUP(A2,IF(AND(B2>='[Dataset 2.xlsx]Sheet1'!B2:B6,B2<='[Dataset 2.xlsx]Sheet1'!C2:C6),'[Dataset 2.xlsx]Sheet1'!A2:D6),4,0),"UNKNOWN")

    It seems to be working but do a lot of testing with other data, you might need to make this an array formula (use Ctrl-Shift-Enter).
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    A variation on a theme:

    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    @Special-K: I don't think your formula will work if the names are in a different order in the two datasets.

    My formula distinguishes between "not present" and "unknown"

    Not sure what will happen in either formula if names are duplicated.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    12-23-2015
    Location
    Amsterdam
    MS-Off Ver
    latest
    Posts
    11

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    I tried both formulas, but I keep getting this error..? How can I fix this?

    error.jpg

  6. #6
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,082

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    UPDATE: Corrected my formula, it SHOULD be Array Formula (Ctrl-Shift-Enter)

    =IFERROR(VLOOKUP(A2,IF(B2>='[Dataset 2.xlsx]Sheet1'!B$2:B$6,IF(B2<='[Dataset 2.xlsx]Sheet1'!C$2:C$6,'[Dataset 2.xlsx]Sheet1'!A$2:D$6)),4,0),"UNKNOWN")

  7. #7
    Registered User
    Join Date
    12-23-2015
    Location
    Amsterdam
    MS-Off Ver
    latest
    Posts
    11

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    It worked! Thank you both sooooooooo much!!

    I got the error because my Excel uses ; instead of '

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  9. #9
    Registered User
    Join Date
    12-23-2015
    Location
    Amsterdam
    MS-Off Ver
    latest
    Posts
    11

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    So, I opened this thread again, cause I came accross some thing that needs to be changed.

    Everything should be exactly as explained above, BUT the number should also be shown when the end date field is empty. So this should be the rule: Show Number if te date from Dataset 1 falls between STart and end date from Dataset 2 OR falls after the startdate from dataset 2 is the end date is empty. I added new datasets to this post.


    =IF(ISNA(MATCH($A2,'[Dataset 2.xlsx]Sheet1'!$A:$A,0)),"not present",

    IF(AND($B2>=VLOOKUP($A2,'[Dataset 2.xlsx]Sheet1'!$A:$D,2,FALSE),

    OR(ISEMPTY($B2); $B2<=VLOOKUP($A2,'[Dataset 2.xlsx]Sheet1'!$A:$D,3,FALSE))),

    VLOOKUP($A2,'[Dataset 2.xlsx]Sheet1'!$A:$D,4,FALSE),"UNKNOWN"))

    I tried changing the formula to this, but for some reason its not working properly. Anyone?
    Attached Files Attached Files

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,509

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    That's not the way it works. The question has been asked and answered, hence ... solved.

    If you have a new question, albeit as a follow up to the original question, please start a new thread.

    Regards, TMS

  11. #11
    Registered User
    Join Date
    12-23-2015
    Location
    Amsterdam
    MS-Off Ver
    latest
    Posts
    11

    Re: VLOOKUP + AND/IF with 3 conditions, using 2 datasets.

    Sorry about that. I will mark it as solved and open a new thread.

+ 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] VBA vlookup conditions
    By yukioh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-21-2015, 01:28 PM
  2. [SOLVED] vlookup with 2 conditions
    By rrcrossman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-21-2015, 01:47 PM
  3. VLOOKUP with several conditions
    By NulExcel in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-03-2014, 12:44 PM
  4. [SOLVED] Excel 2007 - vlookup/index/match with two datasets on two sheets
    By deevusone in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-23-2014, 04:47 PM
  5. [SOLVED] Vlookup - Country conditions (Multiple conditions)
    By dluhut in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-26-2013, 11:42 AM
  6. [SOLVED] Vlookup with 2 conditions
    By ryanch69 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-19-2012, 05:05 AM
  7. Vlookup using 2 conditions
    By Jambruins in forum Excel General
    Replies: 3
    Last Post: 11-15-2005, 10:20 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