“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.
startOfMonth(utcNow())
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.
addDays(addToTime(startOfMonth(utcNow()),1,'Month'),-1,'dd')
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.
addDays(addToTime(startOfMonth(utcNow()),1,'Month'),-7,'dd')
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.
Summary
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.
good post. thank you!
How do I test out my scheduled flow on Power Automate to make sure that it sends on every last Thursday of the month? Do I have to enter the start date as 1 April 2024, so that the email will be sent on 28 March 2024, and subsequently will continue running every 4 weeks on every last Thursday?
Hello MT,
the best way would be to wait until the last Thursday, but I guess that’s not always the option. I do it by adjusting the logic towards the nearest day, e.g. 1st Thursday to validate the functionality and then just change the numbers to make it the 4th Thursday while making a note to check it on that exact day again (and fix it if it doesn’t work properly).
Very helpful! What’s the best way to make this work for every other month?