I'm building a scheduled cloud flow in Power Automate that needs to run only on the last Monday of each month. How can I check if the current date is the last Monday of the current month using Power Automate expressions?
If the flow runs today (September 30th, 2024), the trigger should be true and all actions would run
Using a trigger condition would be fairly hard to support so I wouldn't go down that path unless you really want to, it would be quite verbose. I'm not sure if you wanted to do that or not but I suggest steering clear of it anyway.
These expressions in the flow will do it for you. After the last step, you could have a condition to terminate or not depending on the outcome.
These are the steps and conditions ...
Initialize Current Date
I've just done this with a date from my own timezone.
convertFromUtc(utcNow(), 'AUS Eastern Standard Time')
Is Monday
This will provide a boolean result if the day you're running it on is a Monday.
equals(dayOfWeek(variables('Current Date')), 1)
Is Within 7 Days Of EOM
This is the trickier one. This determines how many days are left between now and the end of the month. There may be a better way but this works.
lessOrEquals(sub(int(formatDateTime(addDays(concat(formatDateTime(variables('Current Date'), 'yyyy-MM'), '-01'), -1), 'dd')), int(formatDateTime(variables('Current Date'), 'dd'))), 7)
Initialize Is Last Monday Of Month
If the last two operations equal true, it's the last Monday of the week.
and(outputs('Is_Monday'), outputs('Is_Within_7_Days_Of_EOM'))
That should give you what you need.