“I’d like to send a reminder on the last Friday in each month, how can I schedule it in Power Automate given various month length?”
When scheduling recurrent flows for a specific day in a month, it can go two ways. You can get the day from the beginning of a month, e.g. first or second Tuesday in a month, or you can take it from the end. While taking it from the beginning is very straightforward, from the end it’s a bit more complicated due to the different length of each month. The day must be always within the last 7 days of the month, but how do you get it if a month can have between 28 and 31 days?
Get the last day of the month
Since each month can have a different number of days, the first step is to get the number for the current month. Unfortunately, Power Automate doesn’t have any expression that would give you the end of a month, but it has an expression to give you the start of a month. Using the startOfMonth(…) expression you’ll get start of the current month, no matter what day it is today.
But that’s the start of this month and you need the end of this month, which is exactly 1 month – 1 day away from the start. Add a month to that date, and remove 1 day with addToTime(…) and addDays(…) expressions. Using the ‘dd’ format you’ll get only the number for the last day in the current month.
Check if today’s date is in the last 7 days
Now, when you’ve got the last date in the month, you can use it in a trigger condition. If it’s the last Friday (or any other day) in the month, it must be in the last 7 days. That means you’ll need borders, the day must be between the last day of the month and the last day of the month -6 days.
Use the expression above as one of the borders, the last day of the month. The other expression would then be very similar, subtracting 7 days instead of 1.
Convert the number into an integer with the int(…) expression, and check if today’s date fits in between: last day of the month -6 <= today <= last day of the month.
@and( lessOrEquals(int(utcNow('dd')),int(addDays(addToTime(startOfMonth(utcNow()),1,'Month'),-1,'dd'))), greaterOrEquals(int(utcNow('dd')),int(addDays(addToTime(startOfMonth(utcNow()),1,'Month'),-7,'dd'))) )
You can then use it as a trigger condition in the recurrence trigger.
Such trigger condition will guarantee that the flow will run only if it’s the last week in the month. Combine it with the specific day and you’re done.
It’s a bit more complicated to schedule a Power Automate flow to run on the last specific day of the month than scheduling it from the beginning. Before you start comparing the dates you must get the dates for the last 7 days in each month, but from then on it’s the same approach. Select which day it should be, and check if the date fits in the range of the last 7 days.
1 thought on “Schedule Power Automate flow to run only last Friday of the month”
good post. thank you!