Sending an e-mail notification the last working day of the month
Inspired by a request from @EJack in the following post, I've created a flow in the Power Automate, which sends an e-mail notification the last working day of the month, except holidays.
Because I can see many use case scenarios for it, I tried to publish it as a template. Some months passed since I have submitted my flow, and it is still not available as a template. Unfortunately, there are no clear rules about submitting templates, no notification about if your template has been released to the pool of templates or rejected. I guess Microsoft still needs to work on that part a bit.
Where is the template?
I have published the flow at my GitHub repository. Feel free to download and import it to your tenant. But be aware that it doesn't honor any holidays but weekends only.
How does it work?
Let's assume that our first day of the working week is Monday, and we do not work during the weekend, on Saturday and Sunday. How would you count the last working day of the month?
First, you should find out what is the weekday on the last day of the month. Unfortunate at the time I write this article, there is no function which returns the last day of the month. You have to use the workaround described below. If you would like to have such a function in Power Automate, please vote on the user's voice here. The idea is still "under review" since December 2018.
To get the last day of the current month, count backward one day from the first day of the next month.
You can use the formula:
subtractFromTime(startOfMonth(addToTime(utcNow(),1,'Month')),1,'Day')
or even more simple:
addDays(startOfMonth(addToTime(utcNow(),1,'Month')),-1)
But the last day of the month can be a weekend (Saturday or Sunday). If this is so, you simply continue counting days backward until you hit Friday.
Now, when you know which day is the last working one in a given month, all you need to do is to compare if this is today. If true, you can trigger whatever action you want.
Note: weekdays can be checked using dayOfWeek() function. It returns numbers starting from 0, which is Sunday and ending on 6, which is Saturday.
To avoid unnecessary API calls, the flow is using trigger conditions which I described in the article "Trigger conditions - filling the information gap", and runs only the last 4 days of the month, which I found enough to address all possible cases.
Challenge for you!
How to respect national holidays?
*This post is locked for comments