I'm trying to calculate 3 days from today, but not include weekend or holidays, but - date

The workday function should work for this. I have a Range called "Holidays". The problem is that workdays doesn't count the weekend days. I need to count the weekend days. BUT, if the 3rd day comes on a weekend or a holiday choose the next non-weekend or non-holiday day. A2 is the Effective Date of the contract, which is the start date. I'm trying to calculate the day on which the Earnest Money is due. See the attached chart as to how it should calculate.
=if(OR(A5="",A5>workday(A2,3,Holidays)),workday(A2,3,Holidays),"") is the formula I have but it works for Effective dates that fall on a Sunday, Monday, Tuesday and Wednesday, but not for Effective dates that fall on a Thursday, Friday, Saturday.

Starting from Today
Use this formula to get the dates starting from today
={ArrayFormula(
VLOOKUP(WEEKDAY(SEQUENCE(7,1,TODAY(),1),2),
{SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},2)),
BYROW(SEQUENCE(7,1,TODAY(),1),
LAMBDA(d, VLOOKUP(WEEKDAY(IF(IFNA(MATCH(d+3,F2:F13*1,0),"")="",d+3,d+4),2),
{SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},2)))}
Starting from Monday
={ArrayFormula(
VLOOKUP(WEEKDAY(SEQUENCE(7,1,TODAY()-WEEKDAY(TODAY(),3),1),2),
{SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},2)),
BYROW(SEQUENCE(7,1,TODAY()-WEEKDAY(TODAY(),3),1),
LAMBDA(d, VLOOKUP(WEEKDAY(IF(IFNA(MATCH(d+3,F2:F13*1,0),"")="",d+3,d+4),2),
{SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},2)))}
Starting from Monday using Lambda
Starting from the current week monday.
=ArrayFormula(LAMBDA(vl,wd,
{VLOOKUP(WEEKDAY(wd,2),vl,2),
BYROW(wd,LAMBDA(d, VLOOKUP(WEEKDAY(IF(IFNA(MATCH(d+3,F2:F13*1,0),"")="",d+3,d+4),2),vl,2)))})
({SEQUENCE(7),{"Monday";"Tuesday";"Wednesday";"Thursday";"Friday";"Saturday";"Sunday"}},
SEQUENCE(7,1,TODAY()-WEEKDAY(TODAY(),3),1)))
Explanation
You need the Calendar Year 20xx Legal Public Holidays to skip one day if matched the legal holidays date after adding 3 days.
Used formulas help
BYROW - SEQUENCE - TODAY - LAMBDA - VLOOKUP - IF - IFNA - MATCH - ARRAYFORMULA

Related

RRULE for every other week except last week of month

I need an RRULE for every other Saturday except the last week of the month. I tried to create one with a weekly frequency, but didn't know how to apply an exception for the last week of the month:
RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SA
I also tried creating a rule with a monthly frequency, which allowed me to skip the last week of the month, but I didn't know how to make it every other week:
RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SA;BYSETPOS=-2,-3,-4,-5
I looked through the specification, but I'm not seeing anything that makes this possible.
The secret to the solution here is that BYMONTHDAY can be negative like BYSETPOS. This allows one to exclude the last 7 days of each month even though the number of days in the month varies. Your DTSTART should be on a SATURDAY, so one doesn't really need the BYDAY=SA
This rrule works in google calendar (if DTSTART is on Saturday and generally for any every 2nd week but not the last week rule for any day of week specified by the DTSTART):
RRULE:FREQ=WEEKLY;INTERVAL=2;BYMONTHDAY=-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,-21,-22,-23,-24,-25,-26,-27,-28,-29,-30,-31
See test calendar:
https://calendar.google.com/calendar/u/0?cid=ZXBwdWE4N2RwZm5xODVic3JydDJzaXFsY3NAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ
Spec: https://datatracker.ietf.org/doc/html/rfc2445#page-43
and
https://icalevents.com/2447-need-to-know-the-possible-combinations-for-repeating-dates-an-ical-cheatsheet/ for the expansion & contraction (limiting) rules & combinations

Trigger Azure Data Factory Pipeline on second Friday from end of month and on Tues, Wed and Thurs of the same week

I need a Pipeline to trigger on the Monthend week (Tues, Wed, Thurs and Friday) of a month.
Monthend is defined as,
"Last but one" Friday Or
Second Friday from the end of the month.
For Example, For month of June 2021, 18th is the Monthend (Orange color as shown in the image)
Calendar Image
If its just on Monthend i.e. Second Friday from the end of calendar month, its easy. Just use Occurrance as -2 and day as Friday in the Scheduled trigger and add to a pipeline to trigger,
"schedule": {
"monthlyOccurrences": [
{
"day": "Friday",
"occurrence": -2
}
]
}
but I also need to run on the Tues, Wed and Thurs of the same week, which I find it difficult as these weekdays can be second or third from the end of the calendar month. For example: For June 2021, as shown in the image, I also need to run on 15th (Third Tuesday from the end of calendar month), 16th (Third Wednesday from the end of calendar month), 17th (Second Thursday from the end of calendar month).
Can you let me know if this can be implemented using triggers of Azure data factory? If not, any otherways of implementing? Thank You!
The scheduled trigger alone is not capable of that logic (as of 2021-05-04). Easiest solution would be to use some other scheduling application.
For a purely Data-Factory solution, schedule the trigger for all the days the desired days could possibly occur on. Then modify the pipeline to do logic to determine whether the current day is actually one of the desired days.
Implementation details and sample code
The logic:
Find the last day of the month (First of the next month less 1 day).
Subtract a week so you are in the second-to-last week
Loop over [0,-1,-2,-3,-4,-5,-6] as number of days to add to the date. This produces the dates of each day of the week.
Use the dayOfWeek function to change the date into which day of the week it is
Filter to get the Friday date
Ask whether today is between the Friday date and Friday date - 3 days

How to calculate the weekend when counting a date range in Google Sheets?

I have the below columns
StartDate EndDate CountDay
01 May 20 05 May 20 ?
As you see, 01 May is Friday, so from 01-05 May if we count all days including weekend it will be 4 days.
What I want is on column "CountDay" it only counts the Workdays, not the weekend.
SO the expected result would be 2.
Anyone know how to do it using a formula in Google Sheets?
Do you consider Fridays as part of the weekend?
If yes, then you could also try the following formula:
=NETWORKDAYS.INTL(A10, B10,"0000111")
If not, please use this formula:
=NETWORKDAYS.INTL(A10, B10)
How the formulas work.
By using the function NETWORKDAYS.INTL we can "adjust" the weekend (non-working weekdays) to our liking.
In this case we account Fridays as our non-working weekdays by using as the 3rd parameter 0000111 instead of the default 0000011 where every 0 represents a working weekday and every 1 a non-working weekday.
(Very useful for people working part-time)
Someone who has part-time work on only Mondays, Wednesdays and Fridays and wants to calculate the working days Friday, 1 May 2020 - Tuesday, 30 June 2020 could adjust the formula to:
=NETWORKDAYS.INTL(A10, B10,"0101011")
As explained on the official Google help page for NETWORKDAYS.INTL
weekend – [ OPTIONAL – 1 by default ] – A number or string representing which days of the week are considered weekends.
String method: Weekends can be specified using seven 0s and 1s, where the first number in the set represents Monday and the last number is for Sunday. A zero means that the day is a work day, a 1 means that the day is a weekend. For example, “0000011” would mean Saturday and Sunday are weekends.
Number method: Instead of using the string method above, a single number can be used. 1 = Saturday/Sunday are weekends, 2 = Sunday/Monday and this pattern repeats until 7 = Friday/Saturday. 11 = Sunday is the only weekend day, 12 = Monday is the only weekend day and this pattern repeats until 17 = Saturday is the only weekend day.
I just found how to do it:
=if(weeknum(A10)<weeknum(B10),B10-A10-2*(weeknum(B10)-weeknum(A10)),B10-A10)
something like that

RRULE for the weekend including the first sunday of a month

We have a event every year on the weekend (Fr-Su) that includes the first Sunday of June. How would I create a iCalendar Event that expresses these three days (whole day events)?
Creating a rule for the first Sunday is easy. But for the Saturday and Friday, I did not succeed to create a rule that counts backwards (RFC 5545 says INTERVAL, COUNT must be positive]. Moreover I could not think of a different expression that would start from the Friday - it could be the last Friday of May, but also the first in June.
The RRRULE specification in RFC 5545 is lacking in this regard. The INTERVAL and COUNT values are for the repeating events, not the event itself. I've come across a similar issue when trying to define the USA day "Black Friday", the day after the 4th Thursday in November (Friday after Thanksgiving). The 4th Friday in November could occur the day after the 4th Thursday, or the prior week. There is not a way that I have found to make a RRULE for this situation.
I believe you will need to code the events individually instead of using a recurring rule.
RRULE:FREQ=YEARLY;BYDAY=FR;BYMONTH=5,6;BYSETPOS=2;BYMONTHDAY=-2,-1,1,2,3,4,5,6,7' seems to do the trick.
How can I write an ICS file for the Friday before the first Saturday of the month? led me to the right track: with 'BYMONTHDAY' I can count backwards from the end of the month.
The Friday before the first Sunday of the next month can be the last or the second to last day of the previous month, or up to the 5th day of the month. If I include May and June, I will get a set that includes the day. 'BYSETPOS' allows me to choose the second of the found Fridays. To always have the second in the set being my desired day, I include the 6th and 7th day of the month, which gives me a stable first Friday in May. Possibly matched additional Fridays in June are discarded by 'BYSETPOS' anyway.
Extending this to Saturday is simple, and the first Sunday of June is trivial.
I developed the rule with rrule.js
https://jakubroztocil.github.io/rrule/#/rfc/RRULE:BYDAY=FR;BYMONTH=5,6;BYSETPOS=2;BYMONTHDAY=-2,-1,1,2,3,4,5,6,7

Representing repetitive dates

Repetitive Dates:
Billing cycles come in a lot of different formats, for example: "the first of the month", "third Friday of the month", or "first weekday on or after 21st day after the 13th of the month" (thanks visa!). My goal is to be able to represent these different billing cycles in one easily parsed database text field.
You forgot weekend processing. If my bill is due on a Sunday, I want it to show up on Friday. That kind of thing. I think there are three possibilities:
Always before the weekend
Always after the weekend
If it's Saturday, Friday, and if it's Sunday, Monday
Current solution:
YYYY/MM/DD+YY/MM/DD+DOW
all blocks (delimited by +) are optional as well as all parts of each block.
first block denotes the starting date
if blank - denotes today
if missing portion - denotes all... ie "//12" would denote the 12th of the month every month.
negative denotes counting from the end of the period.. ie "//-1" denotes the last day of the month
overruns are carried into the next month ie "//40" would be 40 days after the first of the month
second block denotes the change in date between repetitions
if blank - set date (from first block)
Add present portions - ie "/1/" means every month after the given starting date
third block denotes the day of the week the calculated date should be moved to
available are [m,t,w,r,f,s,d,b] (7 days of the week, "business day")
Calculation:
Calculation start on the date specified in the first block, filling in the missing portions with the date the record is added.
the DOW is then added to get a valid starting date. This is the first date of the event.
the next date is calculated by adding the second block to the last calculated first block and adding the DOW to get the next date.
Examples:
on march 12th, 2008 - "2008/3/12"
the first of the month every month - "//1+/1/"
third Friday of the month every month - "//21+/1/+f"
first weekday on or after 21st day after the 13th of the month - "//34+/1/+b"
every 2 weeks from today - "+//14"
last day of every second month starting with march - "/3/-1+/2/"