I'm trying to calculate the number of months in a given time range that fall within 2019.
My data looks like this:
I changed the format of my Start Date and End Date columns to "date". The "Duration in months" and output column have number formatting.
I approached it as follows:
If Start Date (year) < 2019 AND End date (year) = 2019, take the number of months between 1-1-2019 and the end date.
If start Date (year) < 2019 AND End date (year) > 2019, the number of months in 2019 = 12
If start Date (year) = 2019 AND End date (year) = 2019, take the number of months between Start Date and End date.
If start Date (year) = 2019 AND End date (year) > 2019, take the number of months between Start Date and 1-1-2020.
For all other cases, the number of months = 0.
I then followed the instructions from this website for nested IF functions.
I came up with the following formula: (Edit: changed last datedif to 2020 instead of 2019)
=IF(AND(YEAR(A3)<2019;YEAR(C3)=2019);DATEDIF(DATE(2019;1;1);C3;"m");IF(AND(YEAR(A3)<2019;YEAR(C3)>2019);12;IF(AND(YEAR(A3)=2019;YEAR(C3)=2019);DATEDIF(A3;C3;"m");IF(AND(YEAR(A3)=2019;YEAR(C3)>2019); DATEDIF(A3;DATE(2020;1;1);m);0))))
For the first 4 rows, it correctly returns 12.
For row 7 and 8, however, it returns #NAME? .
No matter what I try, I can't seem to get it to work. Any ideas on how I can solve this?
Much appreciated!
Amy
For the entire formula you have been consistent, apart from the last IF statement, where you went wrong within your DATEDIF( statement:
DATEDIF(A3;DATE(2019;1;1);m);0)
First of all you forgot to put m in quotes: "m"
Secondly you accidentally swapped the Date and Cell references, so it would have resolved #NUM. The full correct formula should be:
=IF(AND(YEAR(A7)<2019;YEAR(C7)=2019);DATEDIF(DATE(2019;1;1);C7;"m");IF(AND(YEAR(A7)<2019;YEAR(C7)>2019);12;IF(AND(YEAR(A7)=2019;YEAR(C7)=2019);DATEDIF(A7;C7;"m");IF(AND(YEAR(A7)=2019;YEAR(C7)>2019);DATEDIF(DATE(2019;1;1);A7;"m");0))))
Which will give you the result 4.
Alternatively, the following will give you the amount of full months between two dates. This works with your sample where your dates start on the first day of a month:
Formula in D2:
=SUMPRODUCT((DATE(2019,ROW($1:$12),1)>=A2)*(DATE(2019,ROW($1:$12),1)<=C2))
You've missed the quotes round the final "m" - try
=IF(AND(YEAR(A3)<2019;YEAR(C3)=2019);DATEDIF(DATE(2019;1;1);C3;"m");IF(AND(YEAR(A3)<2019;YEAR(C3)>2019);12;IF(AND(YEAR(A3)=2019;YEAR(C3)=2019);DATEDIF(A3;C3;"m");IF(AND(YEAR(A3)=2019;YEAR(C3)>2019); DATEDIF(A3;DATE(2019;1;1);"m");0))))
Related
I'm using the following formulas to obtain the start date and end date of the week number, given the week number and the year:
Start of week:=MAX(DATE(A2,1,1),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+(B2-1)*7+1)
End of week: =MIN(DATE(A2+1,1,0),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+B2*7)
It seems to work well except that week 1 of 2019 begins on 31-12-2018 but my formula for the start date of the week 1 shows it as 01-01-2019. What is the problem with my formula?
Just subtract 6 from the end date formula
=(MIN(DATE(A2+1,1,0),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+B2*7))-6
As I noted in my comment, the easiest way is just to subtract 6 from your end date. If your data is in a table, your formula would be =[#EndDate]-6. Otherwise, it would be something like =E2-6.
I've got data in a spreadsheet that's formatted YYYYMM and I need to convert it to Month Year format (i.e. 201406 -> June 2014)
I'm using RIGHT() and LEFT() to pull the corresponding bits from the initial data cells, but I can't figure out how to turn the month number into a month name (i.e. 06 -> June, 01 -> January, etc.)
I've tried TEXT(RIGHT(B2,2),"mmmm") which only returns January regardless of the number inputted.
Ideally this should be easy, so, any thoughts? Thanks.
You can use DATE([Year],[Month],[Day]) passing any values for year and day. Just note that this will make the actual value of the cell different to 12 though.
Excel will be reading 12 as a date which will be 12 days after 00/01/1900 (this is 0 as a date) returning 12/01/1900 which is in January.
TEXT(DATE(1,B2,1),"mmmm")
To make 201406 -> June 2014, The Date() formula would do pretty good job indeed. This is the whole formula that would make the transition:
=TEXT(DATE(LEFT(A1,4),RIGHT(A1,2),1),"MMMM YYYY")
Or something hardcoded as this can work:
=CHOOSE(B1,"January","February","March","April","May","June","July")
Another way is to add "01" to the end of your number so you can format it to look like a date, and then return the month from it.
=Text($A$1 & "01","####-##-##") will return 2014-06-01.
=TEXT("2014-06-01","mmmm yyyy") will return June 2014.
So....
=TEXT(TEXT($A$1 & "01","####-##-##"),"mmmm yyyy") returns June 2014.
I need an Excel formula that takes a given day and provides the next upcoming Thursday of that week. I have a list of dates with time stamp attached:
Date Week Ending
10/5/2015 10/8/2015
10/11/2015 10/15/2015
10/21/2015 10/22/2015
10/27/2015 10/29/2015
I want to convert it to the weekending. The example is of my date and the "Week Ending" I want the formula to show.
Assuming Date is in A1, if #Grade 'Eh' Bacon's solution is not working for you and given your mention of time stamp attached, maybe treat your dates as text and say, in B2 and copied down to suit:
=LEFT(A2,10)+(7-WEEKDAY(LEFT(A2,10),15))
Assuming your data is in A1, the formula is simply:
=A1+(7-WEEKDAY(A1,15))
Weekday(A1,15) gives the number of the day of the week of a given date, and the option ,15 says use a week starting with Fri and ending with Thurs. So, a given date, + (7-Weekday()) will give you the number of days required to get to the 'week ending with the Thursday on x date'.
If you want a Thursday to return the same date, then try:
=A1+7-WEEKDAY(A1+2)
The more generalized version would be:
=A1+7-WEEKDAY(A1+7-DOW)
where DOW (DayOfWeek) translates
Sun = 1
Mon = 2
...
Sat = 7
i need an excel formula to calculate the total days remaining for a cell: end date minus todays date plus extension days(maybe 30-90 amount is in a cell) i have tried =days360(today's date,end date + number of extension days) in a different cell but it isn't giving me the correct total
It's giving me the wrong amount of days. I have a formula calculating my end date as well, is that causing a problem =SUM(start date+90+#of extension days)
One possible reason could be your usage of the DAYS360 formula. That uses a 360-day calendar and assumes all months are 30 days. Therefore if you are covering a range where this would have an effect, you will see a difference. For example, with the range 1/1/2013 to 6/1/2013, subtracting the two dates returns 31+28+31+30+31 = 151, compared to DAYS360, which returns 30*5 = 150.
Try just doing basic subtraction, which will also work on dates:
=<End Date> - TODAY() + <Extension>
I've got a column full of dates. How can I check that column to find which date is within a month of todays date, and then return it?
If there is no date within a month, just return blank
Lets say my dates are:
01-Jan-12
01-Apr-12
01-Jul-12
01-Oct-12
01-Jan-13
The code im using is below. A:A is the range of the dates above
=MIN(IF(A:A>TODAY(),A:A))
The issue im having is that if I use the above, it returns 01/01/12 and not 01/01/13. Also, if I change the dates so the next date is December 1st 2012, it still returns 01/01/12
So you really just want the earliest date if that's within a month? If so perhaps try
=IF(MIN(A:A)-TODAY()<=30,MIN(A:A),"")
Assumes dates in column A
If you have past and future dates try this formula
=IFERROR(SMALL(IF(A2:A100>=TODAY(),IF(A2:A100<=TODAY()+30,A2:A100)),1),"")
confirmed with CTRL+SHIFT+ENTER
or for exactly 1 month (rather than 30 days) try using EDATE, i.e.
=IFERROR(SMALL(IF(A2:A100>=TODAY(),IF(A2:A100<=EDATE(TODAY(),1),A2:A100)),1),"")