+ Reply to Thread
Results 1 to 7 of 7

Use of DATE(YEAR($F7)+$G7,12,31) in an IF statement

  1. #1
    Registered User
    Join Date
    06-20-2011
    Location
    Reston, VA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Use of DATE(YEAR($F7)+$G7,12,31) in an IF statement

    I'm trying to use the function =DATE(YEAR($F7)+$G7,12,31) in an IF statement but the results are mixed.

    Please refer to the attached excel file to review a sample worksheet layout and data content.

    Beginning in Cell O6 I entered this formula =IF(YEAR(O$1)>DATE(YEAR($F6)+$G6,12,31),0,1) and copied it through Cell Y6. For Cells O6 thru S6 (years 2014 thru 2018) I expected the formula to report 1 (one) and in years 2019 through 2024 I expected a 0 (zero). Instead I received a 1 in all years. What did I do wrong?

    Beginning in Cell O7, I incorporated the above formula with a VLookup function. This formula again tests if the year in, for example, cell O$1 (i.e., 12/31/2014) is greater than the "end year" that is calculate using cells $F7 and G7 (Date(Year(F7)+G7,12,31) and - if true report 0, else perform the VLookup function. I copied the formula in Cell O7 through to Cell Y7 and on the attached Excel file you will see some mixed results.

    Beginning in Cell O8 thru Y8, I've entered the correct values, which are manually calculated.

    Thank you for any help you can provide in helping me make sense of what the formula in row 6 and 7 should be.
    Attached Files Attached Files

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,967

    Re: Use of DATE(YEAR($F7)+$G7,12,31) in an IF statement

    I will take a look at your file, but I can already see where I think the problem is...
    YEAR(O$1) till give you a 4-digit number (2012 for instance)
    DATE(YEAR($F6)+$G6,12,31) will give you a 5-digit number (41558 for today, for instance)
    4 digits will never ne greater than 5 digits, so you will always get 1

    edit: Yup, I was right, try this instead...
    =IF(YEAR(O$1)>YEAR($F6)+$G6,0,1)
    Last edited by FDibbins; 10-11-2013 at 05:21 PM.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Use of DATE(YEAR($F7)+$G7,12,31) in an IF statement

    The first issue I see is the IF(YEAR(O$1)>DATE(YEAR($F6)+$G6,12,31),0,1)

    You're pulling just a year out a date and then comparing it to a whole date. The year will never be larger than the value of a given date.

    Either omit the first year reference, or just compare straight values.

    =IF(O$1>DATE(YEAR($F6)+$G6,12,31),0,1)

    or

    =IF(YEAR(O$1)>YEAR($F6)+$G6,0,1)



    Edit: Yeah, what he said.

  4. #4
    Registered User
    Join Date
    06-20-2011
    Location
    Reston, VA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Use of DATE(YEAR($F7)+$G7,12,31) in an IF statement

    Thanks a million - your fix works wonderfully in all row 6 cells. Years O1 thru S1 report a "1" while the remaining rows now report a zero. That is very good.

    However, when I tried adding the formula to the row 7 formula with the VLOOKUP function it seems to work in all cells except cell S7 (year 2018), which still results in zero. I tried using >= in the formula but it still reported a zero. Also, the values in cells Q7 thru S7 do not match the manually calculated values in row 8. Any ideas?

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,967

    Re: Use of DATE(YEAR($F7)+$G7,12,31) in an IF statement

    You are getting a 0 hrere because that is what the vlookup is returning

  6. #6
    Registered User
    Join Date
    06-20-2011
    Location
    Reston, VA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Use of DATE(YEAR($F7)+$G7,12,31) in an IF statement

    Thank you. Now that you've pointed me in the right direction, I think I know what's wrong. Sure wish I had your Excel knowledge.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,967

    Re: Use of DATE(YEAR($F7)+$G7,12,31) in an IF statement

    Happy tp help

+ 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. Replies: 3
    Last Post: 09-04-2013, 10:49 AM
  2. [SOLVED] Year on Year data review compared to todays date
    By mintribe in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-24-2013, 06:19 AM
  3. [SOLVED] Keeping a date as current year, even though formula determines previous year
    By dropanddrive03 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-28-2013, 08:31 PM
  4. [SOLVED] Count days for specific year falling within in multi-year date range
    By jslo2013 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-04-2012, 05:58 PM
  5. Replies: 3
    Last Post: 08-14-2012, 05:14 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