+ Reply to Thread
Results 1 to 14 of 14

compare dates using 2 conditions

  1. #1
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365, Excel, Version 2402
    Posts
    184

    compare dates using 2 conditions

    Appreciate if someone could help me here.
    I need to do a test against an ID to see if a date is greater than another date based on a 'type' indicator.

    For example:

    ID Date Type
    1 31/01/2011 I
    1 31/01/2011 A
    1 31/12/2011 A
    1 31/12/2011 C

    The test is: If date of ID 1 Type C is > date of ID 1 of Type I return a yes, otherwise return no. In this case the answer would be Yes.

    Example workbook attached. I have to do this with 1000 different records hence the need for a formula approach, which I don't how to do.

    Thanks
    Attached Files Attached Files
    Last edited by reddwarf; 09-08-2011 at 10:24 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-23-2011
    Location
    Lahore PK
    MS-Off Ver
    Excel 2007, 2013
    Posts
    627

    Re: compare dates using 2 conditions

    attatch file may be helpful
    Attached Files Attached Files
    Azam
    If you want to say Thank you to a member, click the reputation icon (Star) in the left bottom of the post.
    For prompt answer, be descriptive, concise, short, direct, and to-the-point.

  3. #3
    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: compare dates using 2 conditions

    Try this array formula in D2
    Please Login or Register  to view this content.
    Confirm with Ctrl+Shift+Enter not just Enter.
    Drag/Fill Down.

    Note
    You have blanks in Column C, I have assumed that they should be read as "I"
    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.

  4. #4
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365, Excel, Version 2402
    Posts
    184

    Re: compare dates using 2 conditions

    Thanks for your quick reply.
    I entered your formula using Ctrl+Shift+Enter.
    Almost there....while it seemed to be working, as a test, I changed one of the dates of 'I' to a date greater than 'C' but 'Yes' was still being reported whereas the formula should return no. I even refreshed the data but no luck.

    Here is the sample data I used and the output

    ID Date Type Test
    1 31/01/2012 I
    1 31/01/2011 A
    1 31/12/2011 A
    1 31/12/2011 C Yes

  5. #5
    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: compare dates using 2 conditions

    My apology, forgot to finish the formula, missed the INDEX bit ...

    Try this array formula
    Please Login or Register  to view this content.
    Confirm with Ctrl+Shift+Enter not just Enter.
    Drag/Fill Down.

    [EDIT]
    You might need to use >= rather than > for when the dates are equal.
    Last edited by Marcol; 09-07-2011 at 08:54 AM.

  6. #6
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365, Excel, Version 2402
    Posts
    184

    Re: compare dates using 2 conditions

    Hi,
    Thanks again. This new formula works but only where the first line of data has type 'I', but in the example I used (ID 1), type 'I' is on the 2nd line and this date is greater than the date returned by type 'C', so the forumal should return a 'no' but instead it returns a 'yes'?

    Updated workbook attached. Any thoughts?
    Attached Files Attached Files

  7. #7
    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: compare dates using 2 conditions

    I must be missing something, but it looks to me that it returns "No", as it should, in your last workbook ...

    Do you have calculation set to Automatic?
    Last edited by Marcol; 09-07-2011 at 10:57 AM.

  8. #8
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365, Excel, Version 2402
    Posts
    184

    Re: compare dates using 2 conditions

    Cell D5 def reads yes but should read no. See screenshot. Calculation is set on Automatic and I have pressed F9 a few times. I am not sure what it going on? I am using Excel 2003 with Vista.
    Attached Images Attached Images

  9. #9
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365, Excel, Version 2402
    Posts
    184

    Re: compare dates using 2 conditions

    The sort order seems to be affecting the output too. For example, if you sort by ID and then by Type your formula returns different results?

  10. #10
    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: compare dates using 2 conditions

    Are you sure your calculation options are set to Automatic?

    All is okay with my copy of your file

    [EDIT]
    It's the blanks in the Types that are causing the problem when sorting, are there blanks in your actual sheet?
    Last edited by Marcol; 09-07-2011 at 11:35 AM.

  11. #11
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365, Excel, Version 2402
    Posts
    184

    Re: compare dates using 2 conditions

    Yes, calculation options are set to automatic - see attached screenshot
    I tried my workbook on a colleague's pc, who is also using Excel 2003, and still the same results. His calculations options are set to automatic too.

    I have no idea why the formula isn't working correctly for me but is for you
    Attached Images Attached Images

  12. #12
    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: compare dates using 2 conditions

    Try this formula, it should handle the sorting with blanks in Types.
    Please Login or Register  to view this content.
    Confirm with Ctrl+Shift+Enter not just Enter.
    Drag/Fill Down.

    Have a look at this workbook
    Attached Files Attached Files
    Last edited by Marcol; 09-07-2011 at 12:20 PM. Reason: Re-checked attachment

  13. #13
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365, Excel, Version 2402
    Posts
    184

    Re: compare dates using 2 conditions

    Hi Marcol,
    Thanks for your work so far!
    I downloaded your test workbook, which looked fine when I first opended it, but when I changed C2 from 'A' to 'I' I get #NUM! in your array formulas - there is nothing I can do to make the #NUM! disappear except open and close the workbook.
    Also, I changed K5 from 'I' to 'A' and K2 from 'A' to 'I' and I get #N/A at L4.
    Finally, I tried my original workbook on my personal laptop last night at home and I still get the same errors reported yesterday - my personal laptop also runs Excel 2003 but on Win 7?

    New screenshot attached
    Attached Images Attached Images
    Last edited by reddwarf; 09-08-2011 at 05:24 AM. Reason: typo

  14. #14
    Forum Contributor
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Microsoft 365, Excel, Version 2402
    Posts
    184

    Re: compare dates using 2 conditions

    problem solved using a combination of Marcol's formula and Azam Ali's solution.
    Thanks

+ 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