Wednesday, 26 February 2025

Schedule a power automate cloud flow to run only on 3rd working day of the month

 In Power Automate, scheduling a cloud flow to run on a specific working day of the month (excluding weekends) can be challenging. This article demonstrates how to configure a Power Automate cloud flow that executes only on the 3rd working day of the month using a trigger condition.

Understanding the Requirement

A working day refers to Monday to Friday, excluding weekends (Saturday and Sunday). The 3rd working day of the month can fall on different calendar dates depending on when weekends occur.

For example:

  • If the 1st day of the month is a Monday, then the 3rd working day is Wednesday (3rd).

  • If the 1st day of the month is a Saturday, then the 3rd working day is Wednesday (5th).

  • If the 1st day of the month is a Sunday, then the 3rd working day is Thursday (4th).

Setting Up the Flow

Step 1: Create a Scheduled Cloud Flow

  1. Sign in to Power Automate.

  2. Click on Create and choose Scheduled cloud flow.

  3. Set a recurrence trigger (e.g., daily at 12:00 AM UTC).

Step 2: Apply the Trigger Condition

To ensure the flow runs only on the 3rd working day of the month, use the following trigger condition:

@and(
    or(
        and(
            equals(dayOfMonth(utcNow()),3),
            not(equals(dayOfWeek(utcNow()),0)),
            not(equals(dayOfWeek(addDays(utcNow(),-1)),0)),
            not(equals(dayOfWeek(addDays(utcNow(),-2)),0)),
            not(equals(dayOfWeek(utcNow()),6)),
            not(equals(dayOfWeek(addDays(utcNow(),-1)),6)),
            not(equals(dayOfWeek(addDays(utcNow(),-2)),6))
        ),
        and(
            equals(dayOfMonth(utcNow()),4),
            or(
                equals(dayOfWeek(addDays(utcNow(),-1)),6),
                equals(dayOfWeek(addDays(utcNow(),-2)),6),
                equals(dayOfWeek(addDays(utcNow(),-3)),6)
            ),
            not(equals(dayOfWeek(utcNow()),0)),
            not(equals(dayOfWeek(utcNow()),6)),
            not(equals(dayOfWeek(addDays(utcNow(),-1)),0)),
            not(equals(dayOfWeek(addDays(utcNow(),-2)),0)),
            not(equals(dayOfWeek(addDays(utcNow(),-3)),0))
        ),
        and(
            equals(dayOfMonth(utcNow()),4),
            or(
                equals(dayOfWeek(addDays(utcNow(),-1)),0),
                equals(dayOfWeek(addDays(utcNow(),-2)),0),
                equals(dayOfWeek(addDays(utcNow(),-3)),0)
            ),
            not(equals(dayOfWeek(utcNow()),6)),
            not(equals(dayOfWeek(utcNow()),0)),
            not(equals(dayOfWeek(addDays(utcNow(),-1)),6)),
            not(equals(dayOfWeek(addDays(utcNow(),-2)),6)),
            not(equals(dayOfWeek(addDays(utcNow(),-3)),6))
        ),
        and(
            equals(dayOfMonth(utcNow()),5),
            not(equals(dayOfWeek(utcNow()),0)),
            not(equals(dayOfWeek(utcNow()),6)),
            or(
                equals(dayOfWeek(addDays(utcNow(),-4)),6),
                equals(dayOfWeek(addDays(utcNow(),-3)),6),
                equals(dayOfWeek(addDays(utcNow(),-2)),6),
                equals(dayOfWeek(addDays(utcNow(),-1)),6)
            ),
            or(
                equals(dayOfWeek(addDays(utcNow(),-4)),0),
                equals(dayOfWeek(addDays(utcNow(),-3)),0),
                equals(dayOfWeek(addDays(utcNow(),-2)),0),
                equals(dayOfWeek(addDays(utcNow(),-1)),0)
            )
        )
    )
)

Step 3: Apply the Trigger Condition in Power Automate

  1. Click on the Recurrence trigger.

  2. Expand Settings.

  3. Scroll down to Trigger Conditions and paste the above condition.

  4. Save the flow.

How the Condition Works

  • The expression first checks if the current day is the 3rd calendar day of the month and that it is not a weekend.

  • If the 1st, 2nd, or 3rd day of the month falls on a weekend, the expression shifts the condition to check for the 4th or 5th day.

  • The logic accounts for cases where weekends extend the 3rd working day further into the month.

No comments:

Post a Comment