Last working day of the month

Posted by

I had a question been asked on how to calculate the last day of the month, taking into account weekends. Here is my version. You can adjust the logic as needed based on your specific requirements and any regional differences in working days.

What is the use case?

Calculating the last working day of the month in Power Automate offers a practical solution for various business needs. From ensuring timely financial transactions and reporting to meeting project deadlines and regulatory compliance, knowing the last working day facilitates streamlined processes and efficient operations such as sending a report at the end of the month. By automating this calculation, organizations can schedule tasks effectively, meet deadlines with confidence, and optimize resource planning

How to build one using Power Automate

Calculating the last working day of the month in Power Automate involves the following steps

  1. Get the current date
  2. Find the last day
  3. Check if was weekend
  4. Return the last date

Compose – Get Current date

utcNow()

Compose – Get last day

formatDateTime(subtractFromTime(startOfMonth(addToTime(outputs('Compose_-__Get_current_date'), 1, 'Month')), 1, 'Day'), 'yyyy-MM-dd')

Switch

dayOfWeek(outputs('Compose_-_Get_last_day'))

Case – Saturday

addDays(outputs('Compose_-_Get_last_day'),-1)

Case – Sunday

addDays(outputs('Compose_-_Get_last_day'),-2)

In Power Automate, you can use the “dayOfWeek” function to determine the day of the week for a given date. This function returns a numeric value, where Sunday is 0, Monday is 1, Tuesday is 2, and so on, up to Saturday, which is 6. I subtract days accordingly to find the last working day.

Leave a Reply

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