Returning Modified Following business date while building Quarterly calendar - excel-2003

Trying to build a quarterly calendar of working business days (adjusted by holidays).
I am using =edate (A1,4), the only problem is that this function does not adjust for business days. Ideally I would wrap the formula using =workday(edate(A1,4),0,USD_Hols) but it seems that I cannot just add "0" for the formula to return the next business day.
Does anyone know how to get the next business day and also if next business day falls in the next month return the nearest previous business day?
Thanks
Paco

I think this works based on your description on comments. I'm not quite sure what you mean by "previous" in the comment. Below, I'm assuming that it means A1, if A1 is a workday, or the workday before A1 if A1 is not a workday:
=IF(MONTH(WORKDAY(A1,1,USD_Hols))=MONTH(A1),WORKDAY(A1,1,USD_Hols),WORKDAY(WORKDAY(A1,1,USD_Hols),0-1,USD_Hols))
I haven't used workday functions much. One thing I notice is that a 0 argument for days seems to return the date in A1 even if it's not a workday. That's why I included the nested IFs in the ValueIfFalse part of the main IF. It forces it to the next workday and then the one previous to that.

You must add the worksheetfunction to the Workday to Excel 2010
This is correct:
Function NextBiz(d As Range, holidays As Range) As Date
If WorksheetFunction.Weekday(d) = 7 Or WorksheetFunction.Weekday(d) = 1 Or WorksheetFunction.CountIf(holidays, d) > 0 Then
NextBiz = WorksheetFunction.WorkDay(d, 1, holidays)
Else: NextBiz = d
End If
End Function

Related

How to make a condition inside a query function on sheets?

I've been trying to get a list of people who finish their work shift at an specific our, I have not had any problem with this since I've used just a query function:
=QUERY(A1:K48,"select A where B = '7:00 AM' OR C = 'Sunday' OR D = 'Sunday' OR K = TRUE",0)
So, if someone ends their work shift at 7:00 AM or someone rests on Sunday the formula will return these people's names.
Unfortunately, I'm struggling with the next step since those workers work an extra hour or half extra hour some specific days and I was not be able to include in the formula.
For instance, if today is Sunday and today is the Sean long day in which he has to work one extra hour I would like to this Query Formula doesn't includes the Sean's name at 7:00 AM instead of it I would like to include the Sean's name until 8:00 AM. To do this I add "not" in the query formula:
=QUERY(A1:K48,"select A where B = '7:00 AM' AND NOT E matches 'Sunday' OR C = 'Sunday' OR D = 'Sunday' OR K = TRUE",0)
To indicate that Sean is still working, and the formula shouldn't include his name, but now I don't know how to get Sean's name at 8:00 AM.
This is the sheet where I'm working on this Query: Sheet
https://docs.google.com/spreadsheets/d/1Vk95yM8On5nLlFljFerzDH4IG8dZkOgKyHzX36uUWOQ/edit?usp=sharing
To get a clearer idea: I'm getting a list based on column B, C and D values(normal shift days) but before of getting this result I would like to based the list on column E and column F data (long day and hour of the long day) and then if there is no data to take from the E and F column run the first formula.
I hope someone could help me with this I'll be so obliged. Thank you!

Can i create a sum using a key? Absence tracker

I’ve been tasked with creating an absence tracker that will monitor holidays and sickness - I have created the basic layout and a key which determines holiday = H half day morning =Hd1 absence = A etc ...
So the premise is obviously if employee 1 is on holiday you would enter H in the relevant date cell, off sock you would enter A.
What I’m struggling with is the correct formula to add them up each month so absence will be separate and not so much of an issue, but say they have Monday on holiday, and Tuesday as a morning on holiday and then they’re off on compassionate leave on Friday at the end of the month there would be 3 days authorised leave, I’m confused how I put that in a formula.
Try something like this, using countif formula:
=countif(D$6:D$34,$C2)
My solution is available here:
https://docs.google.com/spreadsheets/d/1_oCCsuvseJUqrjWgjDKesON9CSFLZTXxQvYAG8T5Cwk/copy

COUNTIFS date in row is a workday

Ok, so what I'm trying to do is for each month count the number of workdays, minus public holidays.
B2 -- the current year
E2:E13 -- the first day of each month
F2:F13 -- the amount of days (workday or otherwise) in that month, that year
G2:G13 -- the amount of WORK days in that month (i.e. the formula I'm trying ot write)
A8:A -- the public holidays
I can take these and create a formula (here for G2)
=NETWORKDAYS(CONCATENATE("1.",MONTH(E2),".",$B$2),CONCATENATE(F2,".",MONTH(E2),".",$B$2), $A$8:A)
(which leverages the date format dd.mm.yyyy)
The problem with that is that some of these holidays are only half a day off, whereas this formula will give people the full day off.
So an approach could be to simply add half a day back in for every half day off that was wrongfully counted as a full day off, that month.
Assuming I have
C8:C -- is the holiday in the A cell of the same row a half-day?
That turns our formula into
=NETWORKDAYS(CONCATENATE("1.",MONTH(E2),".",$B$2),CONCATENATE(F2,".",MONTH(E2),".",$B$2), $A$8:A)+COUNTIFS($A$8:A,">"&EOMONTH(E2,-1),$A$8:A,"<"&EOMONTH(E2,0)+1,$C$8:C,TRUE)*0.5
(EDIT: example sheet)
But now here's the problem: that holiday may fall on a weekend.
So if a holiday that happens to be half a day off accidentally lies on a Sunday, say, we've just wrongfully added an extra half day of work.
What I need is an additional condition that will evaluate to "true" iff the holiday date is a workday, something along
[...]+COUNTIFS([...], $A$8:A, NETWORKDAYS(ROW,ROW) > 0)*0.5
I have no idea how to reference the row like that, though.
The easy way out would be a helper column that would calculate this boolean for me, but that's ugly as unlike the 'half-day' column, we do not want the user to be able to modify these values so having them see the column will just confuse them.)
How do I write the condition in the countifs?
I have found a simple solution without using countifs. The result you are looking for is the sum of three values:
Result = Working days in a month - Full holidays days - Half holidays days * 0.5
To do this, we will start by calculating the workdays in a month, the workdays minus full holidays and the workdays minus half holidays
WD: =NETWORKDAYS( CONCATENATE("1.",MONTH(E5),".",$B$2), CONCATENATE(CONCATENATE(F5,".",MONTH(E5),".",$B$2))
WD_FULL_H :=NETWORKDAYS( CONCATENATE("1.",MONTH(E5),".",$B$2), CONCATENATE(F5,".",MONTH(E5),".",$B$2), filter(A8:A,C8:C=FALSE)))
WD_HALF_H: =NETWORKDAYS( CONCATENATE("1.",MONTH(E5),".",$B$2), CONCATENATE(F5,".",MONTH(E5),".",$B$2), filter(A8:A,C8:C=TRUE)).
In this way we make sure that any vacation that coincides with a public holiday does not alter the final result. Next, we calculate the final working days. To do this we need to get how many full and half holidays we have in the month, which we get by subtracting the number of working days in the month:
FINAL WD: WD - (WD - WD_FULL_H) - (WD - WD_HALF_H) * 0.5
Simplifying:
FINAL WD: WD_FULL_H - (WD - WD_HALF_H) * 0.5
Finally, without auxiliary calculations:
FINAL WD:
=NETWORKDAYS(
CONCATENATE("1.",MONTH(E5),".",$B$2),
CONCATENATE(F5,".",MONTH(E5),".",$B$2),
filter(A8:A,C8:C=FALSE))
-
(NETWORKDAYS(
CONCATENATE("1.",MONTH(E5),".",$B$2),
CONCATENATE(F5,".",MONTH(E5),".",$B$2)))
-
NETWORKDAYS(
CONCATENATE("1.",MONTH(E5),".",$B$2),
CONCATENATE(F5,".",MONTH(E5),".",$B$2),
filter(A8:A,C8:C=TRUE)))
*0.5
UPDATED FORMULA:
I think this should do it. though there are probably other, maybe even tidier ways.
It adds back in half days if it finds matches in a FILTER().
=ARRAYFORMULA(NETWORKDAYS(E2,EOMONTH(E2,0),A$8:A$18)+IFERROR(FILTER(C$8:C$18,EOMONTH(A$8:A$18,0)=EOMONTH(E2,0),C$8:C$18,WEEKDAY(A8:A18,2<6))/2))

Google spreadsheet, comparing durations

I calculated a duration between two times, e.g. between 9:00 am and 11:00 am. So far so good. Now I need to decide if this duration is less 6 hours.
I do remember that this was pain in the s in excel but nevertheless I tried it the simple way:
=IF(E2 < 06:00:00; "y"; "n")
of course that didn't work. Next:
=IF(DURATION(E2) < DURATION(06:00:00); "y"; "n")
still, it didn't work.
So, okay, how can I compare two duration?
Divide hours by 24:
=IF(E2 < 6/24, "y", "n")
Value is E2 is a formatted time, actually 1 hour is 1/24, 1 day is 1.
Some info about date and time formats here:
http://www.excel-easy.com/examples/date-time-formats.html
You can also use the HOUR function if you want to
=if(HOUR(E2)<6,ʺyesʺ,ʺnoʺ)
or
=if(E2<time(6,0,0),ʺyesʺ,ʺnoʺ)
(if you write 06:00:00 in a formula it takes it as a string not a time)
but as I'm sure someone is about to point out, the first formula above gives the wrong answer for durations of more than a day (because it takes the hour part of a datetime).
What I find interesting is that you can assume for a worksheet formula that dates and times are represented as whole numbers (days) and fractions (parts of a day) just like in Excel. If you ever have to deal with them in Google App Scripts, you suddenly find that it's object-oriented and you have no choice but to use methods like hour() to manipulate them.
I needed to use the equivalent of:
=if(TIMEVALUE(E2)<6/24, "yes", "no")

How to utilize date add function in Google spreadsheet?

I believe the issue I am having now should be much easier in MS Excel. However, since my company uses Google Spreadsheet so I have to figure out a way.
Basically, I have a cell that contains a date value like "12/19/11", and I have another cell contains a value like "DT 30". The task assigned to me is to add the value 30(days) to the date, so the result should be "1/19/2012".
I did some trying in Google Spreadsheet, I have two questions. The first is to how to extract the numeric value "30" out of the string "DT 30", the second question is that, there seems to be no date add function built in Google Docs.
Could any experts offer some suggestions?
I like to keep it simple. If A1 holds the date and B1 holds the number of months to add, then
=date(year(A1),month(A1)+B1,day(A1))
would calculate the required result. The same way could be used for days or years
To extract a numeric value out of your string you can use these 2 functions (Assuming you have your value in cell 'A1'):
=VALUE(REGEXEXTRACT(A1, "\d+"))
This will get you a numeric value.
I've found no date add function in docs, but you can convert your date into internal date number and then add days number (If your value is in cell 'A2'):
=DATEVALUE(A2) + 30
I hope this will help.
You can just add the number to the cell with the date.
so if A1: 12/3/2012 and A2: =A1+7 then A2 would display 12/10/2012
You can use the DATE(Year;Month;Day) to make operations on date:
Examples:
=DATE(2013;3;8 + 30) give the result... 7 april 2013 !
=DATE(2013;3 + 15; 8) give the result... 8 june 2014 !
It's very surprising but it works...
The direct use of EDATE(Start_date, months) do the job of ADDDate.
Example:
Consider A1 = 20/08/2012 and A2 = 3
=edate(A1; A2)
Would calculate 20/11/2012
PS: dd/mm/yyyy format in my example
As with #kidbrax's answer, you can use the + to add days. To get this to work I had to explicitly declare my cell data as being a date:
A1: =DATE(2014, 03, 28)
A2: =A1+1
Value of A2 is now 29th March 2014
Using pretty much the same approach as used by Burnash, for the final result you can use ...
=regexextract(A1,"[0-9]+")+A2
where A1 houses the string with text and number
and A2 houses the date of interest
what's wrong with simple add and convert back?
if A1 is a date field, and A2 hold the number of days to add:
=TO_DATE((DATEVALUE(A1)+A2)
=TO_DATE(TO_PURE_NUMBER(Insert Date cell, i.e. AM4)+[how many days to add in numbers, e.g. 3 days])
Looks like in practice:
=TO_DATE(TO_PURE_NUMBER(AM4)+3)
Essentially you are converting the date into a pure number and back into a date again.
In a fresh spreadsheet (US locale) with 12/19/11 in A1 and DT 30 in B1 then:
=A1+right(B1,2)
in say C1 returns 1/18/12.
As a string function RIGHT returns Text but that can be coerced into a number when adding. In adding a number to dates unity is treated as one day. Within (very wide) limits, months and even years are adjusted automatically.

Resources