Compare if year in date is prior to today's year - excel

I have a date in the format of "4/26/2013". I want to see if that date is prior than the current year, whatever that current year may be (don't want to hardcode 2013) and count how many of the rows match that criteria. Say there are 6 rows of dates in that format:
=COUNTIF(C2:C7, YEAR(Today()))
This threw an error. I'm new to Excel, so I probably made a huge mistake! Can anyone see what is wrong with this?
Thanks!

If C2:C7 contain dates you need to compare them to the 1st of January in the current year, e.g.
=COUNTIF(C2:C7,"<"&DATE(YEAR(TODAY()),1,1))
or you can use SUMPRODUCT like this
=SUMPRODUCT((YEAR(C2:C7)<YEAR(TODAY()))*(C2:C7<>""))

I just figured it out. My syntax was wrong. The answer to the above example was:
=COUNTIF(C2:C7, ">"&YEAR(TODAY()))
That returned the number of dates in C2 - C7 that were prior to the current year.

Related

Counting the matches of a date in time periods in Excel

I am trying to find a (reasonably elegant) formula to find out how often a date appears in a list of date ranges.
In my example I have 4 date ranges, defined by a start date (A2:A5) and by an end date (B2:B5). Below I have a list of dates for which I would like to know how often a date appears in any of those 4 ranges. The only solution I came up with was to check for each range if the date is in there. The formula becomes quite lengthy with the number of periods and is not flexible if more periods are added later.
Here the time periods:
And here where I try to retrieve the number of matches given a date:
My formula is here for B11 (yielding 3 given the input of 10/Sep/2021):
=IF(AND($A11>=$A$2,$A11<=$B$2),1,0)+IF(AND($A11>=$A$3,$A11<=$B$3),1,0)+IF(AND($A11>=$A$4,$A11<=$B$4),1,0)+IF(AND($A11>=$A$5,$A11<=$B$5),1,0)
Any ideas appreciated!
Using COUNTIFS:
=COUNTIFS($A$2:$A$5,"<="&A11,$B$2:$B$5,">="&A11)

Index Match to match date between two dates

I have a date column B that are dates. My Fiscal year begins April 1 and ends March 31, I have my date ranges below:
Here is my formula including named ranges. I'm getting N/A error, and I'm not sure what I'm doing wrong.
{=INDEX(fiscalyear,MATCH(1,(startdate>=B2)*(enddate<=B2),0))}
You can get rid of the lookup with:
="FY" & YEAR(EOMONTH(B2,9))
Since any fiscal year starts right after a fiscal year ends you can just use:
=INDEX(fiscalyear,MATCH(B2,startdate,1))
Although both of the previous answers are correct and the formulas are simpler than the original one, I would like to point out where the original problem was - the comparison operators were swapped there.
It was:
{=INDEX(fiscalyear,MATCH(1,(startdate>=B2)*(enddate<=B2),0))}
Must be:
{=INDEX(fiscalyear,MATCH(1,(startdate<=B2)*(enddate>=B2),0))}

Counting Number of Months between Two Dates in Excel

So I am attempting to simply count the number of months bewtween an earlier date and today, which will be in the B:B column; once the number of months have been counted, the result is then multiplied by 28, then added back to the original date. Note the requirement: Result >= Today, so basically if the result is less than today it needs to add another 28 days. The current formula I made only works if the dates are in the current year (and I am not 100% sure if this formula works, it appears to so far though.)
Here is my defunct formula, but maybe someone can get a general idea from my above comments and the below formula of what I am attempting to achieve here:
=IF(B89="","",IF(I89="X","LEG",IFERROR(IF((MONTH(TODAY()-B89)*28)+B89<TODAY(),(MONTH(TODAY()-B89)*28)+B89+28,(MONTH(TODAY()-B89)*28)+B89),"Future")))
Thank you in advance for your assistance!
Note: I just want to point out that the reference to I89 is insignificant in the above. I just didn't want to remove it in case I deleted the wrong parenthesis or some other typo, so I decided to leave in there. So basically you would not need to necessarily worry about the first two "IF" statements, nor the IFERROR, unless you just wanted to!
2ND EDIT: Okay I decided to strip down formula, original post's formula is above, the stripped version below:
IF((MONTH(TODAY()-B89)*28)+B89<TODAY(),(MONTH(TODAY()-B89)*28)+B89+28,(MONTH(TODAY()-B89)*28)+B89)
You should not use MONTH() for this purpose as this will lead to wrong results in some cases, and certainly when the B89 date is in another year.
Instead see how many days you are past the last multiple of 28 days since B89, and go back to that date (by subtracting), and then add another 28 to it:
=TODAY() + 28 - MOD((TODAY()-B89), 28)
The earliest date this can give is the date of tomorrow. If today should be an acceptable outcome of the formula, then replace TODAY() with TODAY()-1, which results in this formula:
=TODAY() + 27 - MOD((TODAY()-1-B89), 28)
How about something like this:
=IF(B89="","",IF(I89="X","LEG",IF(IF(B89<=TODAY(),B89+28*IF(AND(B89<TODAY(),TEXT(B89,"mmyy")=TEXT(TODAY(),"mmyy")),"1",(TEXT(TODAY(),"yy")*12+MONTH(TODAY()))-(TEXT(B89,"yy")*12+MONTH(B89))),"Future")<TODAY(),TODAY(),IF(B89<=TODAY(),B89+28*IF(AND(B89<TODAY(),TEXT(B89,"mmyy")=TEXT(TODAY(),"mmyy")),"1",(TEXT(TODAY(),"yy")*12+MONTH(TODAY()))-(TEXT(B89,"yy")*12+MONTH(B89)))))))
Got a little long now, but you have a lot of criteria :)

If Date Exceeds Certain Date Then

How do I set a formula or VBA to get around this?
If Date Listed in Column A + (7 Days) Exceed 5th of Upcoming Month then Do Something.
Its like 5th of Each Month is Deadline.
If Column A = 30th March 2015 +(7days)left = 6th April 2015 then Column B = "HolyCrap" Else "You're Safe"
I would really appreciate some help on this.
Let's try this formula:
=IF(AND(DAY(A1+7)>5,DAY(A1+7)<13),"screwed","safe")
The date in A1 could be in either Date or Number format. You would get the correct Number format after pressing Ctrl+;.
Please test it and let me know if for some date it does not return the correct result.
You can use 3 different functions to achieve this in Excel: IF, TODAY and DAY360.
You need a column to calculate the present date. Use TODAY function for that.
You need a column to calculate the number of days difference between the two dates (that is, the present date and your target date). Use the DAYS360 function for that.
Then on the cell / Column you require to display whatever you want it to display use the IF function. It will help determine if the current date is over or under your specified value in days, and return whatever value you want displayed; overdue, expired, Yes, No etc. Example:
=IF(P2>30,"Expired","Active")

Excel month formula

I want to show specific text for whether something is due for any given month in a financial year or overdue if that month has passed. The formula I am using is as below and works fine until I get to January.
I am using the numerals 7-12 in this formula to represent respective month but am unsure how to ensure the number 1 relates to the next year. For that matter I guess my equation below for overdue for December won't work either.
=IF(MONTH(TODAY())=12,"DUE",IF(MONTH(TODAY())<=12,"",IF(MONTH(TODAY())>=12,"Overdue")))
Any help would be appreciated
Instead of the month number, let A1 equal the first of the month in which it's due. (Note the first of the month is what you'll get if you just type in the month and year, eg August 2014)
=IF(TODAY()<A1,"",IF(TODAY()>EOMONTH(A1,0),"Overdue","Due"))
Here is a solution that you can use. This includes a =YEAR( function and an =AND function to extend on what you already have.
The formula you can use is here.
=IF(AND(MONTH(TODAY())=MONTH(A2),YEAR(TODAY())=YEAR(A2)),"Due",IF(AND(MONTH(TODAY())>MONTH(A2),YEAR(TODAY())>=YEAR(A2)),"Overdue",""))
you can add the year into the comparison which will eliminate your problems with January.
Just wrap the month check and year check in an =AND( function when both conditions are TRUE you can enter your result.

Resources