Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

Schedule Power Automate flow to run only last Friday of the month

Posted on April 10, 2022April 10, 2022 by Tom

“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')
Power Automate schedule last of the 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.

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.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

1 thought on “Schedule Power Automate flow to run only last Friday of the month”

  1. a says:
    May 26, 2022 at 2:52 am

    good post. thank you!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with 1000s of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes