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

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

Related

Azure Synapse Pipeline Date Expression - Last Monday

I have the following azure function that is supposed to retrieve the date of the previous Monday. It works fine except for if the current date is a monday. I need the function to still retrieve the previous monday date if it is Monday or Tuesday. This is due to the time not being updated until middle of day tuesday.
#{formatDateTime( subtractFromTime( utcNow(), sub(dayOfWeek(utcNow()),1), 'Day' ), 'yyyy-MM-dd 00:00:00' )}
I am still learning Azure synapse so I am not sure if I can write an IF statement that accomplishes this or if there is a better way to write it.
I have reproduced the above and able to get the desired result by using the below dynamic content.
#if(greater(dayOfWeek(utcnow()),1),formatDateTime(addDays(subtractFromTime(utcnow(),dayOfWeek(utcnow()),'Day'),1),'yyyy/MM/dd'),formatDateTime(addDays(subtractFromTime(utcnow(),dayOfWeek(utcnow()),'Day'),-6),'yyyy/MM/dd'))
The day of week for a monday from last sunday is 1, so I am checking the current date's day of week is greater than monday or not.
If it is greater (Today is not a Monday), then I am giving last Monday by adding 1 day to the last Sunday.
If it is not, then I am subtracting -6 from the last Sunday which is the previous Monday.
This will work for all days, but we need to change the condition and the number which we are adding and subtracting as per the day we required.
Result:
If you want the result to be Monday even though current date is Monday or Tuesday, then give the expression for Tuesday also in the above condition using or.

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

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

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

How to show date from last monday to sunday?

I am trying to create an Analytics report and I want to set the date range from Monday to Sunday.
I am setting the Start date to: =today()-7 and the End day to =today()-1, but this shows the last 7 days everytime I run the report (say I run it on wednesday, it will show data from wednesday to tuesday).
How can I set the date range so it shows it from last Monday to Sunday?
Short answer
Use WEEKDAY
Explanation
WEEKDAY returns the day of the week.
To get the Monday's date, use this value to subtract it from today's date.
To get the Sunday's date, add 6 to the monday date.
Example
Today =today() 11/14/2016
Weekday =WEEKDAY(B1,3) 0
Start =B1-B2 11/14/2016
End =B3+6 11/20/2016

How to find a Friday after last Wednesday of month?

What iCal RRULE expression should I use to find a Friday after last Wednesday of month? So I need (RRULE:FREQ=MONTHLY;BYDAY=-1WE) + 2 days...
I agree with Evert that this is not possible with a single RRULE.
You can, however, achieve that with a combination of multiple RRULEs.
That way you can split your event into multiple events each one having one of the RRULEs below:
If Wednesday falls on the last or second last day of a month, our Friday will be the 1st or 2nd of the next month
FREQ=MONTHLY;BYMONTHDAY=1,2;BYDAY=1FR
In months with 31 days the earliest date for the last Wednesday is the 25th, so the next Friday will be one of day 27-31:
FREQ=MONTHLY;BYMONTH=1,3,5,7,8,10,12;BYMONTHDAY=27,28,29,30,31;BYDAY=FR
In months with 30 days the earliest date for the last Wednesday is the 24th, so the next Friday will be one of day 26-30:
FREQ=MONTHLY;BYMONTH=4,6,9,11;BYMONTHDAY=26,27,28,29,30;BYDAY=FR
February is a tricky one, because in non-leap years the the Friday we want will be between the 24th and 28th, but in leap years it's between the 25th and 29th. However, within the next 50 years there is only one leap year in which February 24th is a Friday, which is 2040 (check out the result of FREQ=MONTHLY;BYMONTHDAY=24;BYMONTH=2;BYDAY=FR), so the following RRULE will be correct until 2040:
FREQ=MONTHLY;BYMONTH=2;BYMONTHDAY=24,25,26,27,28,29;BYDAY=FR
If you're concerned about the leap years, add an EXDATE like below and you're good for the next 100 years (make these DATE-TIME values if your start date has a time):
EXDATE;VALUE=DATE:20400224,20680224,20960224,21080224
If you know for sure that your clients support multiple RRULEs (which has been deprecated halfheartedly in RFC 5545 but still was perfectly valid in RFC 2445) you could add them into a single event as well, but I wouldn't recommend that.