Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
Menu

Move weekend due date when creating Planner tasks in Power Automate

Posted on August 1, 2021August 1, 2021 by Tom

“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.

Leave a Reply Cancel reply

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

Now available:

The Ultimate Power Automate expressions cheat sheet
Equip yourself with the tool to translate your thoughts into Power Automate expressions!

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.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Format results of date calculation in SharePoint columnJune 29, 2022
  • Why is your Power Automate flow creating duplicatesJune 26, 2022
  • How to create a unique identifier in your Power Automate flowJune 22, 2022
  • How to assign custom SharePoint permission level with Power AutomateJune 19, 2022
  • Remove permissions from a specific SharePoint user with Power AutomateJune 15, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme