+ Reply to Thread
Results 1 to 24 of 24

if values between x and y date each year output yes

  1. #1
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    if values between x and y date each year output yes

    Hi,

    I have data as far back as 2000 and I want to output a value of yes if the date is between two dates for each year. For example if the date is between the 15th of September 2000/1/2/3/4 etc and the 15th of April 2001/2/3/4/5 etc, output yes, otherwise output no. It would be for each 15th of September to 15th of April every year.

    Is there an easy method of doing this?

    I haven't been having much luck in figuring this one out, your help would be very much welcomed.

    Regards,
    Dewey

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: if values between x and y date each year output yes

    Would something like this help? >> =IF(AND(A1>DATE(2000,9,15),A1<DATE(2001,4,15)),"Yes","Nope")
    HTH
    Regards, Jeff

  3. #3
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: if values between x and y date each year output yes

    Or you could put the dates in a cell and then point to the dates instead of hardcoding

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: if values between x and y date each year output yes

    Are you still using Excel 2013?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Quote Originally Posted by jeffreybrown View Post
    =IF(AND(A1>DATE(2000,9,15),A1<DATE(2001,4,15)),"Yes","Nope")
    Thank you for that but that only works for one time period, I would like it to be done for each year, maybe if I put in an or statement for each year but that would make the equation very long.

    Dewey

  6. #6
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Quote Originally Posted by AliGW View Post
    Are you still using Excel 2013?
    Nope using 2019 now, just updated it, I forgot to update it.

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: if values between x and y date each year output yes

    Hi Dewey,

    How about you past a small sample of what you have and what you expect.
    Last edited by jeffreybrown; 10-10-2023 at 12:12 PM.

  8. #8
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    So the attached document is what I have, its a selection of dates between 2000 and 2023.
    I want the values between 15th September 200(n) and 15th April 200(n+1) to output a value. In this case Yes or Nope.

    I have used the formula provided above and inputted it into a long if, or statement.
    The issue with this way is that the formula is long already and I want to add in a formula where if yes comes back calculate X and if no comes back then output 0.


    Is there a way to condense down the or statement?

    Regards,
    Stephen
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: if values between x and y date each year output yes

    Did you try Jeff's suggestion? I was thinking the same kind of strategy -- choose a year (I would choose a leap year) and convert each date to that the same date for that year, then decide if it is in the desired date range or not.

    For an example of how I might implement this:

    1) In E2, Enter =DATE(1900,MONTH(A2),DAY(A2)) [copy/paste/fill down]. This gives me the corresponding date in the year 1900 (erroneously a leap year in Excel and Lotus).
    2) If I understand the logic, if this date is between April 15 and Sept 15, then output "Nope", else output "Yes." =IF(AND(DATE(1900,4,15)<=E2,E2<=DATE(1900,9,15)),"Nope","Yes") or =IF(AND(DATE(1900,4,15)<=E2,E2<=DATE(1900,9,15)),calculation if Nope,calculation if Yes)

    Did I understand correctly, or did I misunderstand something?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: if values between x and y date each year output yes

    Try:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Ben Van Johnson

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: if values between x and y date each year output yes

    The attached file contains a parameter query in Power Query. You select the start and end dates in the fields shown. click on Refresh All and your data is updated.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  12. #12
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: if values between x and y date each year output yes

    For any given year, the number of days from September 15 of that year to January 1 of the following year is always 108 days.
    Therefore, the time period from September 15 of a given year to April 15 of the following year, when adjusted to the same year, also add (+) 108 days. This is true regardless of whether it's a leap year or a regular year.

    So, for any given date, to determine whether it falls within this time frame, you can add (+) 108 days to that date and then compare it with January 1 and August 1.

    If A2 is the original date, then A2 + 108 is the date for calculation. You can compare this date with January 1 and August 1 following year to determine if it falls within the specified time frame. If the date is between January 1 and August 1, the result is "Yes," otherwise, it's "Nope."

    And, the final formula should be:

    Please Login or Register  to view this content.
    P/S: compare with your manual result in row 43, with A43 = 10-Oct-2010, it should be "Yes" as per my formula, but your desired outcome is "Nope"
    Is it correct?
    Attached Files Attached Files
    Quang PT

  13. #13
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Quote Originally Posted by protonLeah View Post
    Try:
    Please Login or Register  to view this content.
    Hi Ben Van Johnson,

    Thank you for that but that returns results that shows out of range when it should show within range. for example it shows the 14th of February as being out of range but it should show it within range

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: if values between x and y date each year output yes

    Administrative Note

    Please don't ignore contributors to your thread - it takes members time to provide suggestions, so acknowledge all solutions offered, even if they don't meet your requirements. Thanks.

  15. #15
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Quote Originally Posted by MrShorty View Post
    Did you try Jeff's suggestion? I was thinking the same kind of strategy -- choose a year (I would choose a leap year) and convert each date to that the same date for that year, then decide if it is in the desired date range or not.


    2) If I understand the logic, if this date is between April 15 and Sept 15, then output "Nope", else output "Yes." =IF(AND(DATE(1900,4,15)<=E2,E2<=DATE(1900,9,15)),"Nope","Yes") or =IF(AND(DATE(1900,4,15)<=E2,E2<=DATE(1900,9,15)),calculation if Nope,calculation if Yes)

    Did I understand correctly, or did I misunderstand something?
    Hi Mr Shorty,

    I did try Jeffs suggestion and it worked, the only "problem" is for it to work for each year, a large equation is required for each year.

    You understood it perfectly.

  16. #16
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Quote Originally Posted by alansidman View Post
    The attached file contains a parameter query in Power Query. You select the start and end dates in the fields shown. click on Refresh All and your data is updated.
    Thank you for that,

    I do not have power query in excel and unsure what it is.

  17. #17
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Quote Originally Posted by bebo021999 View Post
    For any given year, the number of days from September 15 of that year to January 1 of the following year is always 108 days.
    Therefore, the time period from September 15 of a given year to April 15 of the following year, when adjusted to the same year, also add (+) 108 days. This is true regardless of whether it's a leap year or a regular year.

    So, for any given date, to determine whether it falls within this time frame, you can add (+) 108 days to that date and then compare it with January 1 and August 1.

    If A2 is the original date, then A2 + 108 is the date for calculation. You can compare this date with January 1 and August 1 following year to determine if it falls within the specified time frame. If the date is between January 1 and August 1, the result is "Yes," otherwise, it's "Nope."

    And, the final formula should be:

    Please Login or Register  to view this content.
    P/S: compare with your manual result in row 43, with A43 = 10-Oct-2010, it should be "Yes" as per my formula, but your desired outcome is "Nope"
    Is it correct?

    Thank you for this. This is what I was looking for.

    You are correct with respect to the 10th of October, it should have been a Yes.


    I have been looking at the equation, trying to understand it more but finding it difficult to figure out when the equation "knows" it is the 15th of April.

    The first part of the equation checks the data is from 2001 and above, anything below that is outputted as "Nope",

    The OR statement indicates that if the month plus the number of days from the 15th of September to the 1st of January is less than 8, a true statement is outputted, otherwise a false statement is outputted.
    The AND statement indicates that if the month plus the number of days from the 15th of September to the 1st of January is equal to 8 and the date plus number of days from the 15th of September to the 1st of January is equal to 1, a true statement is outputted, otherwise a false statement is outputted.

    The second IF statement indicates that if the OR statement and/or the AND statement outputs a true statement, then "Yes" is outputted, but if neither statements output a true statement, then "Nope" is outputted.


    If I want to change the start date from the 15th of September to the 10th or the 27th, the 108 days would be updated accordingly, but that equation automatically changes the end dates of the 15th of April also by the difference in the new start dates and 108 days.

    Any insight into how the equation "knows" when the 15th of April is reached would be greatly welcomed.

    Dewey

  18. #18
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Quote Originally Posted by AliGW View Post
    Administrative Note

    Please don't ignore contributors to your thread - it takes members time to provide suggestions, so acknowledge all solutions offered, even if they don't meet your requirements. Thanks.
    My apologies if it looked like I was ignoring contributors, I was working through the potential solutions as I saw them before replying back, to know if a solution was working or not and sometimes get distracted by other things.

  19. #19
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: if values between x and y date each year output yes

    I do not have power query in excel and unsure what it is.
    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.

  20. #20
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: if values between x and y date each year output yes

    Quote Originally Posted by deweyirl View Post
    If I want to change the start date from the 15th of September to the 10th or the 27th, the 108 days would be updated accordingly, but that equation automatically changes the end dates of the 15th of April also by the difference in the new start dates and 108 days.
    Any insight into how the equation "knows" when the 15th of April is reached would be greatly welcomed.
    Dewey
    Case 1) From 15-Sep to 1-Jan next year is 108 days. 1-Apr would be added 108 = 1-Aug
    Case 2) From 27-Sep to 1-Jan next year is 113 days. 1-Apr would be added 113 = 6-Aug
    Case 3) From 10-Sep to 1-Jan next year is 96 days. 1-Apr would be added 96 = 20-Jul


    The formula for case 1:
    Please Login or Register  to view this content.
    Old criteria: from 15-Sep to 1-Apr
    add 108 days, New criteria: from 1-Jan to 1-Aug
    New date = initial date + 108
    Then (new date = <1-Aug ) statement equals month from 1 to 7 (<8) or 1-Aug (month=8 and day=1)

    The formula for case 2:
    Please Login or Register  to view this content.
    Old criteria: from 15-Sep to 1-Apr
    add 113 days, New criteria: from 1-Jan to 6-Aug
    New date = initial date + 113
    Then (new date = <6-Aug ) statement equals month from 1 to 7 (<8) or <= 6-Aug (month=8 and day<=6)

    The formula for case 3:
    Please Login or Register  to view this content.
    Old criteria: from 15-Sep to 1-Apr
    add 96 days, New criteria: from 1-Jan to 20-Jul
    New date = initial date + 96
    Then (new date = <20-Jul ) statement equals month from 1 to 6 (<7) or <= 20-Jul (month=7 and day<=20)

    Hope it clear for you now.

  21. #21
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Hi,

    Thank you for the reply and explanation.

    Unfortunately it didn't at the start but I worked out what you were saying.


    There appears to be some mix ups in the Case examples and in Case 3, shouldn't it be <7 and not 6?

    It is also based on the 15th of April and not the 1st of April.

    I think I have adjusted it so that it flows and conveys what your explanation is.



    Ultimately I am trying to also be able to change when the dates start and end, so it might be 17th of September until the 3rd of April.


    I have spent most of the day trying to play around with the formula to make it work, but I am getting no where fast.

    I would post the formula I figured out to date but excel crashed and I didn't save it :/ but will try to recreate it.

    The start dated was always the new date I wanted. For example if I changed the 108 to cell k4 (which counted the difference in the dates between the new start date e.g. 27th September and 1st January) but if I kept the end date the 15th April, it would always increase it to the dated in April that is the difference between the 27th of September and 1st January e.g. instead of the 15th April, it would be 27th April.

    I am trying to edit the formula to allow it reference a cell which mentions the start date and the end date but I'm not having much luck.

    Is it possible with your equation


    Regards,
    Dewey

  22. #22
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: if values between x and y date each year output yes

    Try again with sample in sheet.

    =IF(OR(YEAR(H6)<2001,H6>DATE(YEAR(H6),MONTH($J$2),DAY($J$2))),"Nope","Yes")
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    07-15-2014
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: if values between x and y date each year output yes

    Hi all,

    Thanks for your help but in the end I was able to work it out.

    The attached document is my solution.

    If you input the end date and start date with a year, it will check that the date being reference is less than the day, month and year of the starting date or that the date being referenced is greater than the day, month and year of the end date.

    I have checked it and it appears to work for any start and end date inputted.

    As the data inputted will only be for the years that is relevant, there is no issue with the year being effectively irrelevant in the calculation.

    Thank you all again for your help.

    Kind Regards,
    Dewey
    Attached Files Attached Files

  24. #24
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,916

    Re: if values between x and y date each year output yes

    Thanks for sharing.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered 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. [SOLVED] Sum values of a date range 1 year back today's date
    By PitchNinja in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-21-2021, 02:33 PM
  2. Help! I want to substract year values from two cells with date values
    By cjasso in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2021, 04:11 PM
  3. Replies: 8
    Last Post: 07-23-2020, 04:16 AM
  4. Replies: 1
    Last Post: 04-22-2015, 08:08 AM
  5. formula to output upcoming quarter end date (for a broken fiscal year)
    By canaille in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-22-2014, 05:01 PM
  6. Replies: 3
    Last Post: 09-04-2013, 10:49 AM
  7. sum values against part of a date, year
    By jordiman in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-19-2009, 01:52 PM

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