How do I calculate a date by adding 30 calendar days, where end date must be business day? - excel

I'm wondering if this is possible. I am creating a spreadsheet to track project due dates. Each project must be completed by the 30th calendar day, but must be turned in on a business day.
Currently, I am just adding 30 days to the start date but this means some due dates aren't always accurate. For example, if the 30th day is Saturday, April 2nd, then the real due date would be Friday April 1st.
Is there a way to construct a conditional such that the due date equals the 30th calendar day, unless that falls on a weekend / holiday, where it then falls on the next earliest business day?
I've been struggling to figure out a way to do this.

For English settings in Excel, with a date in A1, in B1 enter:
=IF(TEXT(A1+30,"DDDD")="Sunday",A1+28,IF(TEXT(A1+30,"DDDD")="Saturday",A1+29,A1+30))
This simple-minded approach only handles Saturdays and Sundays, not arbitrary holidays.

I would prefer more elegant way like using WORKDAY.INTL
=WORKDAY.INTL(A2+31,-1,1,E2:E)
Explanation: start date + 31 days (1 day more than maximum calendar days)
then subtract 1 working day - going to last previous working day
Reason: because this formula does know when are weekends (by using variables) and also knows to skip hollydays by a custom list.
here is an example sheet you can use

Revised after comment:
Try this:
=(A4+30)+CHOOSE(WEEKDAY(A4+30),1,0,0,0,0,0,-1)
Your date, in A4, + 30 days, then add an amount of days until the next workday. If A4 + 30 is a Saturday it will subtract 1 day, a Sunday will add 1.

Related

Formula that translates a date to Fiscal Year, Fiscal Period, and Fiscal Week

Working on a formula that will take a date and translate it to the format FYxxPxxWx.
For example. Input the date of 03/22/20 and the formula will give you FY20P06W4 which is correct.
However if you input 02/02/20 the formula will give you FY20P05W2. The correct output would be FY20P05W1. This issue also rears its head with the date 09/29/19. It gives you FY20P12W5. The correct output would be FY20P1W1.
Something else weird happens when you put in the date 04/5/20 you get FY21P07W2 when it should be FY20P07W2.
The formula is
=CONCATENATE("FY",RIGHT(YEAR(DATE(YEAR(D5),MONTH(D5)+(10-1),1)),2),"P",TEXT(CHOOSE(MONTH(D5),4,5,6,7,8,9,10,11,12,1,2,3),"0#"),"W",WEEKNUM(D5,1)-WEEKNUM(DATE(YEAR(D5),MONTH(D5),1),1)+1)
I think this issue is caused by the strange weeks where the the month ends and another begins throwing off the formula.
I do have a formula that calculates the years fiscal year start date
=(DATE(YEAR(TODAY())-1,10,1)-(WEEKDAY(DATE(YEAR(TODAY())-1,10,1),1)))+1
This outputs 09/29/19 as the start date of the Fiscal year as its the same week as 10/1/19 which is the first month of the fiscal year. IF that makes sense.
The separate formulas are
For FY and grabs only last two digits of year
RIGHT(YEAR(DATE(YEAR(D5),MONTH(D5)+(10-1),1)),2)
For Period (gives me a two digit Period
TEXT(CHOOSE(MONTH(D5),4,5,6,7,8,9,10,11,12,1,2,3),"0#")
For Week
WEEKNUM(D5,1)-WEEKNUM(DATE(YEAR(D5),MONTH(D5),1),1)+1)
I believe I have a solution for you. Discussion to follow, but here's the full formula:
=CONCAT("FY",RIGHT(YEAR(D5+91+WEEKDAY(DATE(YEAR(D5),10,1))),2),"P",TEXT(IF(MONTH(D5+(7-WEEKDAY(D5)))<>MONTH(D5),IF(MONTH(D5)=9,1,CHOOSE(MONTH(D5),5,6,7,8,9,10,11,12,1,2,3,4)),CHOOSE(MONTH(D5),4,5,6,7,8,9,10,11,12,1,2,3)),"0#"),"W",ROUNDUP(((D5-IF(MONTH(D5+(7-WEEKDAY(D5)))<>MONTH(D5),DATE(YEAR(D5),MONTH(D5)+1,1)-WEEKDAY(DATE(YEAR(D5),MONTH(D5)+1,1))+1,DATE(YEAR(D5),MONTH(D5),1)-WEEKDAY(DATE(YEAR(D5),MONTH(D5),1))+1))/7)+0.01,0))
One issue is that this still calculates 2/2/2020 the way you said was incorrect. When I verify it against a calendar, though, it seems that FY20P05W02 should be correct. If the week that includes the first of the month begins a new pay period, that would mean 2/1/2020, falling on a Saturday, would be the last day of fiscal week 1. That would make 2/2/2020 the first day of fiscal week 2.
To calculate fiscal year, I used RIGHT(YEAR(D5+91+WEEKDAY(DATE(YEAR(D5),10,1))),2). Since you can count on there always being 91 days from the beginning of October to the end of December, it helps with this calculation. In your formula, you had MONTH(D5)+(10-1), which would push you 9 months out past the month in D5. This explains why your result for 4/5/2020 was off by a year.
Fiscal period was a bit trickier, requiring a couple nested IF statements. I used IF(MONTH(D5+(7-WEEKDAY(D5)))<>MONTH(D5) first to account for days at the end of the month that would fall into the next fiscal period, then IF(MONTH(D5)=9 to account for the few days at the end of September that might fall into the next fiscal year. Days at the end of September would default to 1, days at the end of a month that are included in the next fiscal period use the first CHOOSE function (they need the next month's number), and everything else gets the CHOOSE function as you wrote it.
The fiscal week took a bit more, but in the end I evaluated the beginning of the current fiscal month and subtracted it from the date in D5, then divided by 7 and added 0.01 so that even numbers would round up correctly.
I tested this out over a few years of dates and it seemed to be functioning correctly, but let me know if you have questions or issues.
One thing to consider when using WEEKNUM is that you'll have a week that is counted twice at the beginning of the year unless you use option 21 or ISOWEEKNUM. These give the same result as each other, and ensure that only one week number is assigned to any given day, no matter the year.

Find the trading date every 2 weeks (if Saturday or Sunday, then show Friday date)

For a backtesting trading system, I need to rotation my positions every 2 weeks, BUT if the day is a Saturday or Sunday, I need to take the Friday.
Semi-Monthly updates are made twice a month; mid-month and month end.
Mid-month updates are on the 15th calendar day of each month. Should the 15th be a weekend or holiday, the update will occur on the last trading day prior to the 15th.
For example, if the 15th is a Saturday then the update will occur on the close of Friday the 14th.
I need to return a list of dates of rotation based on a start date and end date.
Let's say, I need every 15 days from January 1st 2018 to 31st December 2018, it should return only the valid dates based on the rules described above.
The formula should be for Google Sheet or Excel.
I tried the following:
It is not returning exactly what I need, since the google sheet googlefinance formula allows to use daily and weekly intervals (1 or 7). See below the googlefinance definition (https://support.google.com/docs/answer/3093281?hl=en):
"interval - [ OPTIONAL ] - The frequency of returned data; either "DAILY" or "WEEKLY".
interval can alternatively be specified as 1 or 7. Other numeric values are disallowed."
You need to be more precise in your specifications. You've provided multiple inconsistent intervals. eg: Two weeks (which would be every 14 days and will always fall on the same weekday); every 15 days (which will NOT be mid-month and EOM over most time periods); mid-month and end-of-month.
I suggest developing formulas for each of your desired intervals.
Once you have developed those relevant formulas, depending on your desired interval, to avoid a date falling on a weekend (or holiday if required for your system), you can use the WORKDAY function:
=WORKDAY(computedDate+1,-1, [holiday])
If your computedDate is on a Saturday, or Sunday; by adding 1 day and then subtracting to the previous workday, Friday will result.
If your trading interval is every Two weeks, you only need to ensure that the First date is not on a Saturday or Sunday. For other intervals, you may have to apply the formula to every computedDate.

Week number of a quarter

I'm trying to get the week number of a given quarter based on the date.
I currently have this formula
=1+(WEEKNUM(EDATE(Y4,-1)))-(WEEKNUM(DATE(YEAR(EDATE(Y4,-1)),
LOOKUP(MONTH(EDATE(Y4,-1)),{1,4,7,10}),1)))
But for January, it should be giving me 1 but it's giving me 10. Any suggestions?
How do you expect this to work at the start and end of the quarter? Default WEEKNUM function starts week 1 on the 1st of January every year and week 2 starts on the next Sunday after 1st January.
Assuming your quarter week numbers should work the same way, i.e. week 1 starts on the 1st of Jan/Apr/Jul/Oct and week 2 starts on the next Sunday then that's actually equivalent to counting Sundays since 6 days back into the previous quarter.
You can do that using NETWORKDAYS.INTL function, i.e. with this formula:
=NETWORKDAYS.INTL(EOMONTH(Y4,MOD(1-MONTH(Y4),-3)-1)-5,Y4,"1111110")
format result as number with no decimal places
NETWORKDAYS.INTL function is available in Excel 2010 and later versions - for older versions of Excel you can get the same results with this formula:
=INT((13-WEEKDAY(Y4)+Y4-EOMONTH(Y4,MOD(1-MONTH(Y4),-3)-1))/7)
(Expanded from comment)
when you choose a date in January, it's going back to December. 12 in your lookup array gives 10 as the result. Perhaps instead of EDATE, you should use EOMONTH(Y4,-1)+1, so you look at the 1st of the current month for your calculation
=1+(WEEKNUM(EOMONTH(Y4,-1)+1))-(WEEKNUM(DATE(YEAR(EOMONTH(Y4,-1)+1), LOOKUP(MONTH(EOMONTH(Y4,-1)+1),{1,4,7,10}),1)))
This is fairly interesting, since it changes with the year, and changes with what day of the week is the "start" of the week. So if a quarter starts on Saturday, and the week starts on a Saturday, the entire week is week 1. However, if it starts on a Sunday, week 1 is only one day long, and week 2 starts on Sunday.
The first question we have is, what day is it?
=DayCheck
Additionally, I'm going to call the start of each quarter the following:
Q1Start = Date(Year(DayCheck),1,1)
Q2Start = Date(Year(DayCheck),4,1)
Q3Start = Date(Year(DayCheck),7,1)
Q4Start = Date(Year(DayCheck),10,1)
The next question is, what's the first day of the week? We have some control over this with the Weekday function. For the sake of keeping it simple, Sunday is the start of the week.
Ok, that's our day. Next, what quarter is it?
`Quarter=ROUNDDOWN(MONTH(O16)/4,0)+1`
This gives us 1 for Q1, 2 for Q2, etc.
What day of the week is it now?
=WEEKDAY(DayCheck,1)
Ok, and now, what week are we on?
=WEEKNUM(DayCheck,1)
I'm going to put it together in a not very elegant fashion. I'm sure there's a better way out there.
=(Quarter=1)*((Weeknum(DayCheck)-WeekNum(Q1Start)+1)+(Quarter=2)*((Weeknum(DayCheck)-WeekNum(Q2Start)+1)+(Quarter=3)*((Weeknum(DayCheck)-WeekNum(Q3Start)+1)+(Quarter=4)*((Weeknum(DayCheck)-WeekNum(Q4Start)+1)
Try this:
=CHOOSE((MOD(WEEKNUM(Y4),13)=0)+1,WEEKNUM(Y4)-(ROUNDDOWN(WEEKNUM(Y4)/13,0)*13),13)
This will get the week number of a given date within a quarter.
I used this in one of my applications so you might be able to use it too. HTH.
Note: If you use 1st day other than Sunday, then adjust the WEEKNUM formula.
Can try this as I got this as combination of 2 formula
=WEEKNUM(A1,1)-(INT((MONTH(A1)-1)/3)*13)
second part - INT((MONTH(A1)-1)/3) gives us the quarter number of previous quarter which then multiplied with 13 weeks/quarter gives us how many weeks have passed in all previous quarter before current quarter.
First part - "WEEKNUM(A1,1)" gives us the week number of current week in the year.
so by deducting all the previous weeks in previous quarters from current week number of year, we get the current week number in current quarter.

Using Excel to calculate multiple future dates

I am working on a revenue report that predicts deposit date related to "Revenue Date" based on observed patterns. For example, one stream of revenue is always deposited the next business day, so I would need a formula that adds one day to anything with a "Revenue Day" identified as Monday through Thursday (because these would be deposited Tuesday-Friday, respectively), and adds three days to a "Revenue Day" identified as Friday (because this would be deposited on Monday), and adds two days for Saturday, and one for Sunday.
I managed to get the correct result for Monday-Thursday using this formula, where G1 is the weekday and H1 is the date:
=IF(OR(G1="MONDAY", G1="TUESDAY", G1="WEDNESDAY", G1="THURSDAY"), H1+1)
Unfortunately, I can't figure out how to also get it to add 3 days to Friday, 2 days to Saturday, and 1 day to Sunday. Is this possible?
Your if formula should take 3 parameters IF(condition, do if condition is true, do if condition is false).
Use ; instead of ,
Sundays does the same this as Moday-Thursday, so no need for a special case for it
... So i would guess that you need something like this :
=IF(OR(G1="SUNDAY";G1="MONDAY";G1="TUESDAY";G1="WEDNESDAY";G1="THURSDAY");H1+1;IF(G1="FRIDAY";H1+3;IF(G1="SATURDAY";H1+2;"bad input")))

Excel function to create due dates that land on a business day

I'm stuck creating a formula that will calculate days before the end of the month then adjust to make sure it is a business day. For example: 30 days before 6/30/2015 is 5/31/2015 which is a Sunday. I need that to adjust to the Friday before.
I'm working on finding the due dates of a number of documents that are due a certain number of days before another date. For example: documents are due 30 days before the last day of the month. However, the number of days varies and the due date needs to fall on a business day (Monday-Friday). Sometimes it's 30 days, sometimes it's 60 days, sometimes it's 30 calendar days + 5 business days, etc.
I've been able to calculate 30 days + 5 business days with the following formula:
=workday(start_date-30,-5)
Any ideas how to adjust this so that I can just have the due date be 30 calendar days before a certain date but also always be a business day?
Using WORKDAY you can use a formula like this:
=WORKDAY(A1+B1+1,-1)
where A1 is your start date and B1 the number of days to add.
You probably need to write a macro function or maybe some nested IF statements in your cell's formula.
Take a look at http://www.mrexcel.com/forum/excel-questions/481558-round-date-nearest-workday.html
That solution moves forward to the nearest workday, but the principle is sound: just subtract instead of add.

Resources