Move weekend due date when creating Planner tasks in Power Automate

“How can I tell my Power Automate flow to create Planner tasks with due date only on working days, to skip weekend and move it to Monday instead?”


When you create Planner tasks automatically with Power Automate, you might automatically calculate also their due date. Take today’s date, add the desired task duration, and get the task due date. But here comes a small complication. If you created tasks manually, you wouldn’t select Saturday or Sunday as the due date. You’d probably move the due date to the next working day: Monday. But Power Automate won’t do that, unless you add the logic by yourself. And this article will show you how.

DayOfWeek(…) expression

The main expression for this solution is the dayOfWeek(…) expression. When you enter a date as a parameter, it’ll return a number from 0 to 6. Using today’s date, it’ll work as below:

dayOfWeek(utcNow())   will return 0 on Sunday
                                  1 on Monday
                                  ...
                                  6 on Saturday

The same logic can be used on any date. It can be a calculated date or a date from other source, e.g. a date of a task imported from an Excel file. Following the Excel example, let’s take the basic expression: if the date cell in Excel is not empty, you use the date. The date must be in the ISO 8601 format.

if(
  equals(items('Apply_to_each')?['DueDate'],''),
    null, 
    items('Apply_to_each')?['DueDate']
)

Ignoring the condition that the value shouldn’t be empty, take just the date dynamic content.

items('Apply_to_each')?['DueDate']

Since it’s a valid date, it can be used in the dayOfWeek(…) expression. It’ll return a number from 0 to 6 depending on the day of the week. But you’re interested only if it’s 0 or 6, the weekend.

dayOfWeek(items('Apply_to_each')?['DueDate'])

Is it Sunday?

If it’s 0, it’s Sunday and you must add 1 day to turn it into Monday. Here you’ll combine it with the if(…) expression as already described in article on empty dates.

if(
  equals(dayOfWeek(items('Apply_to_each')?['DueDate']),0),
    <ifTrue..Sunday>,
    <ifFalse..NotSunday>)
)

If true, it’s Sunday, add 1 more day with the addDays(…) expression.

if(
  equals(dayOfWeek(items('Apply_to_each')?['DueDate']),0),
    addDays(items('Apply_to_each')?['DueDate'],1),
    <ifFalse..NotSunday>
)

Is it Saturday (or Sunday)?

Now it’s time to do the same for Saturday. Extending the expression above, if the condition is false (it’s not Sunday), let’s check if it’s Saturday. If it’s Saturday, you must add 2 days to turn it into Monday.

if(
  equals(dayOfWeek(items('Apply_to_each')?['DueDate']),0),
    addDays(items('Apply_to_each')?['DueDate'],1),
    if(equals(dayOfWeek(items('Apply_to_each')?['DueDate']),6),
       addDays(items('Apply_to_each')?['DueDate'],2),
       <ifFalse..NotSundayNorSaturday>
    )
)

And if it’s not Saturday nor Sunday, you can take the date as is.

if(
   equals(dayOfWeek(items('Apply_to_each')?['DueDate']),0),
     addDays(items('Apply_to_each')?['DueDate'],1),
     if(
       equals(dayOfWeek(items('Apply_to_each')?['DueDate']),6),
         addDays(items('Apply_to_each')?['DueDate'],2),
         items('Apply_to_each')?['DueDate']
     )
)

The last step is to add back the condition if the field is empty.

if(
  equals(items('Apply_to_each')?['DueDate'],''),
    null, 
    if(
      equals(dayOfWeek(items('Apply_to_each')?['DueDate']),0),
        addDays(items('Apply_to_each')?['DueDate'],1),
        if(
          equals(dayOfWeek(items('Apply_to_each')?['DueDate']),6),
            addDays(items('Apply_to_each')?['DueDate'],2),
            items('Apply_to_each')?['DueDate']
        )
    )
)
Power Automate Planner tasks weekend

Summary

The solution above is not limited to skipping weekend when creating Planner tasks with Power Automate. With the dayOfWeek(…) expression you can build many interesting solutions, e.g. to run a flow only on specific day in a specific week in a month. Just remember that the week starts with 0 on Sunday and ends with 6 on Saturday.

But that was only one part of the solution, the other one is the if(…) expression. It’s a powerful expression which can help you save a lot of flow actions. As you can see in the final expression, it’s 3 IFs deep, and you could go much deeper if needed. You could achieve the same functionality with a variable and 3 levels of ‘Conditions’, or you can have 1 composed expression…


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.

Add a Comment

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