Forum Discussion

POSPOS's avatar
POSPOS
Post Partisan
1 year ago
Solved

How to exclude weekends with scheduled flows using Power Automate

Hi All, I have a requirement to schedule a Power BI report as a PPT to users every month on 15th. Requirement is to send on 15th of every month, but if 15th is a weekend (Saturday or Sunday) , then...
  • vojtechsima's avatar
    1 year ago

    POSPOS Hello,

    here's my proposal.

    Recurence every day, then initialize variable as string with this inside of it:

     

    if(
        and(
            not(equals(dayOfWeek(addDays(startOfMonth(utcNow()), 14)), 6)),
            not(equals(dayOfWeek(addDays(startOfMonth(utcNow()), 14)), 0))
        ),
        formatDateTime(addDays(startOfMonth(utcNow()), 14), 'yyyy-MM-dd'),
        if(
            and(
                not(equals(dayOfWeek(addDays(startOfMonth(utcNow()), 15)), 6)),
                not(equals(dayOfWeek(addDays(startOfMonth(utcNow()), 15)), 0))
            ),
            formatDateTime(addDays(startOfMonth(utcNow()), 15), 'yyyy-MM-dd'),
            if(
                and(
                    not(equals(dayOfWeek(addDays(startOfMonth(utcNow()), 16)), 6)),
                    not(equals(dayOfWeek(addDays(startOfMonth(utcNow()), 16)), 0))
                ),
                formatDateTime(addDays(startOfMonth(utcNow()), 16), 'yyyy-MM-dd'),
                null
            )
        )
    )

     

    (code basically checks whether 15th, 16th or 17th is weekend and find the earliest non weekend day to run it).

    This gonna check what's the valid day for the run in the current month.

    Then you have a condition that checks if today is that day and you then put the rest of your actions to the "TRUE" branch.