cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
UpgradeIT
Helper I
Helper I

Create a planner task each month, but exclude the weekend, what function do i need?

Hello Community 🙂

So im relly close now, to have what i need, but need a little help agian 😮

So this power automate plan is working, but how can i make it exclude the weekend, so my plans only comming in working day?. so if i start the script manuel sunday or sataturday its should start monday, and everytime is reach saturday or sunday in other month, its should still be monday. i read on the internet is possible, but can´t find the function i need O:O

 

here is the plan, if someone has a suggestion, plz let me know and ty ❤️

 

UpgradeIT_0-1625419828183.png

formatDateTime(utcNow(),'yyyy-MM-dd')

UpgradeIT_2-1625419897621.png

int(formatDateTime(variables('TaskDate'), 'yyyy'))

UpgradeIT_3-1625419932700.png

 

UpgradeIT_4-1625419951585.png

 

addToTime(outputs('Create_a_task')?['body/dueDateTime'],1,'month')
2 ACCEPTED SOLUTIONS

Accepted Solutions
ccc333ab
Solution Sage
Solution Sage

I thought I saw in the original solution you were adding just 7 days, I see now you are adding a month. So we now need to update the bottom expression to also check for weekend. So in the last Set Variable will need this expression. 

 

But because this expression is getting really big, going to add in a Compose Statement just to make this easier on my brain...

ccc333ab_0-1625441413058.png

Compse Statement is just: 

addToTime(outputs('Create_a_task')?['body/dueDateTime'],1,'month')

Set variable will now be: 

if(equals(dayofWeek(outputs('Compose')), 0),addDays(outputs('Compose'), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(outputs('Compose')), 6),addDays(outputs('Compose'), 2, 'yyyy-MM-dd'), outputs('Compose')))

View solution in original post

UpgradeIT
Helper I
Helper I

hi @ccc333ab :), omg it´s working O:O seems like it, i just tested it to 2023.  relly ty for help i never self figured that if code out by me self ... <3.

 

ty to @fchopo  and @tom_riha for helping me with starting this crazy planner script and ty to @ccc333ab  for help me finish it ❤️ love the community her

UpgradeIT_0-1625442082939.png

if(equals(dayofWeek(utcNow()), 0),addDays(utcNow(), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(utcNow()), 6),addDays(utcNow(), 2, 'yyyy-MM-dd'), utcNow()))

UpgradeIT_1-1625442100500.png

int(formatDateTime(variables('TaskDate'), 'yyyy'))
 
UpgradeIT_2-1625442121351.png
UpgradeIT_3-1625442139473.png

 

addToTime(outputs('Create_a_task')?['body/dueDateTime'],1,'month')
UpgradeIT_4-1625442173102.png

 

if(equals(dayofWeek(outputs('Compose')), 0),addDays(outputs('Compose'), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(outputs('Compose')), 6),addDays(outputs('Compose'), 2, 'yyyy-MM-dd'), outputs('Compose')))
 
as you see here: its look its working ❤️
UpgradeIT_5-1625442228490.png

 

View solution in original post

10 REPLIES 10
ccc333ab
Solution Sage
Solution Sage

I haven't seen your previous posts so I may not have the logic right, but if I understand this correctly, you are trying to create a task, that starts today, but if today is a Weekend, have it start on the following Monday instead. 

 

Then you want to have the task end date be one month from now. But again, if the end date is on a weekend, have it in on the following Monday instead. 

 

So my approach would be: 

 

1. Using your start with setting the variable to today's date. Don't need to as I could just use utcNow() in all my expression, but this works as well. 

ccc333ab_0-1625423286657.png

 

2. I am now going to take this TaskDate and now check to see if it is a Saturday or a Sunday. If it is a Saturday I will add 2 days (to make it Monday). Likewise, if it is a Sunday I will add 1 day to it to make it a Monday. 

 

And I'll do this also for 1 month from now. These are long expressions and I could have done this in multiple steps, and if you want me to I can show you to help explain these, but this will work if you just want to cut/paste. 

ccc333ab_1-1625424264346.png

 

Expression in TaskStart compose statement: 

if(equals(dayofWeek(variables('TaskDate')), 0),addDays(variables('TaskDate'), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(variables('TaskDate')), 6),addDays(variables('TaskDate'), 2, 'yyyy-MM-dd'), variables('TaskDate'))) 

Expression in TaskEnd compose statement: 

if(equals(dayofWeek(addToTime(variables('TaskDate'),1,'Month')), 0),addDays(addToTime(variables('TaskDate'),1,'Month'), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(addToTime(variables('TaskDate'),1,'Month')), 6),addDays(addToTime(variables('TaskDate'),1,'Month'), 2, 'yyyy-MM-dd'), addToTime(variables('TaskDate'),1,'Month','yyyy-MM-dd'))) 

Now you can just use these dates in your Planner Tasks. 

ccc333ab_2-1625424379750.png

 

Hello , @ccc333ab  😉

Ty for help seems like it working, but now the count dont work ,  i mean it set 5 thing to my plan but everyone is same month look picture. if you want whole flow i can send here again. its should have set them diffrent month

 

UpgradeIT_2-1625426087006.png

 

UpgradeIT_1-1625425948730.png

 

UpgradeIT_0-1625425939681.png

 

 

ccc333ab
Solution Sage
Solution Sage

Sorry, I must be missing something. Probably because I didn't see your previous post....so not 100% sure what you are trying to achieve. 

 

What is it you are trying to do with the Apply_to_each? And what would your expected dates be in your task? 

Hello @ccc333ab 

What im trying to do is this.

I have some workstuff, i need to do each month. The workstuff is all time the same, so i want to create a power automate, so it can create this plan for me for the nexst 1 year, so i dont need manuel create this in planner.

 

so the idea is, it need to create a plan for me each month for example nexst 12 month, and the plan must not reach a sataturday or sunday. i dont care what day is it as long is doenst reach a saturday or sunday.   so i can see the plan for nexst 12 month.

 

i see microsoft come with the option first in november that long time to :/, but if this is not possible to do i just wait. 

 

this is the script i got help from the begining before in time https://powerusers.microsoft.com/t5/Building-Flows/Help-how-can-i-create-a-power-automate-for-planne...

and its working fine for 1 week .

 

then i got a little help with this: https://powerusers.microsoft.com/t5/Building-Flows/Create-a-task-in-Planner-each-week-month-and-year...  and adapat the first link flow with the solution from secound link and its working now, but i need the last step, and make it to skip sataturday or sunday, and its working with your solution, but the problem is i cant get it to create for nexst 12 month now 🙂, its doing like you see on the picture from planner


im and we are so close to solve this crazy flow 😮

hope its make sense otherwise let me know, if you need i could take a screenshot of what i have now if you will take a look on it ❤️

 

ccc333ab
Solution Sage
Solution Sage

OK, so I understand now. Go back to your original code that you had working before. 

 

Now what I would do is only check your initial TaskDate is a Saturday or Sunday, and if it is, add 1 or 2 days to make it the Monday.


That should be the only thing you need to do because your original code just adds 7 to this date, which will then always be a Monday. 

 

So your original initialize statement should read:  

ccc333ab_0-1625436792168.png

 

Where expresssion would be: 

if(equals(dayofWeek(variables('TaskDate')), 0),addDays(variables('TaskDate'), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(variables('TaskDate')), 6),addDays(variables('TaskDate'), 2, 'yyyy-MM-dd'), variables('TaskDate'))) 

 

 

Hello @ccc333ab  🙂

something i do wrong ?, mabye something i miss ?, i get a error it said TaskDate' cannot be found.'.

 

UpgradeIT_0-1625438488908.png

if(equals(dayofWeek(variables('TaskDate')), 0),addDays(variables('TaskDate'), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(variables('TaskDate')), 6),addDays(variables('TaskDate'), 2, 'yyyy-MM-dd'), variables('TaskDate')))

UpgradeIT_1-1625438510311.png

int(formatDateTime(variables('TaskDate'), 'yyyy'))

 

UpgradeIT_2-1625438534733.png

addToTime(outputs('Create_a_task')?['body/dueDateTime'],7)

 

ccc333ab
Solution Sage
Solution Sage

OH, I am SO sorry, that was really dumb of me. Goes to show you I should test before I submit a solution but wasn't really thinking when I submitted that.

 

Of course you can't refer to TaskDate in the initialize becuase it deosn't exist yet. So I forgot to just refer to utcNow date...which it origially set. This expression should now work. 

 

if(equals(dayofWeek(utcNow()), 0),addDays(utcNow(), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(utcNow()), 6),addDays(utcNow(), 2, 'yyyy-MM-dd'), utcNow()))

hI @ccc333ab  🙂

Is ok i said ty for you try helping me but after i did what you said

its said now

 

Unable to process template language expressions in action 'Set_variable' inputs at line '1' and column '16855': 'The template language function 'addToTime' expects a timestamp as the first parameter, an interval as the second parameter, a time unit as the third parameter, and an optional format string as the fourth parameter. The function was invoked with '2' parameter(s). Please see https://aka.ms/logicexpressions#AddToTime for usage details.'.

 

and if i change my set variable to: addToTime(outputs('Create_a_task')?['body/dueDateTime'],1,'month'), then is correct. but its still make the plan on a satatur or sunday 😕

UpgradeIT_0-1625440812807.png

 

ccc333ab
Solution Sage
Solution Sage

I thought I saw in the original solution you were adding just 7 days, I see now you are adding a month. So we now need to update the bottom expression to also check for weekend. So in the last Set Variable will need this expression. 

 

But because this expression is getting really big, going to add in a Compose Statement just to make this easier on my brain...

ccc333ab_0-1625441413058.png

Compse Statement is just: 

addToTime(outputs('Create_a_task')?['body/dueDateTime'],1,'month')

Set variable will now be: 

if(equals(dayofWeek(outputs('Compose')), 0),addDays(outputs('Compose'), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(outputs('Compose')), 6),addDays(outputs('Compose'), 2, 'yyyy-MM-dd'), outputs('Compose')))

View solution in original post

UpgradeIT
Helper I
Helper I

hi @ccc333ab :), omg it´s working O:O seems like it, i just tested it to 2023.  relly ty for help i never self figured that if code out by me self ... <3.

 

ty to @fchopo  and @tom_riha for helping me with starting this crazy planner script and ty to @ccc333ab  for help me finish it ❤️ love the community her

UpgradeIT_0-1625442082939.png

if(equals(dayofWeek(utcNow()), 0),addDays(utcNow(), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(utcNow()), 6),addDays(utcNow(), 2, 'yyyy-MM-dd'), utcNow()))

UpgradeIT_1-1625442100500.png

int(formatDateTime(variables('TaskDate'), 'yyyy'))
 
UpgradeIT_2-1625442121351.png
UpgradeIT_3-1625442139473.png

 

addToTime(outputs('Create_a_task')?['body/dueDateTime'],1,'month')
UpgradeIT_4-1625442173102.png

 

if(equals(dayofWeek(outputs('Compose')), 0),addDays(outputs('Compose'), 1, 'yyyy-MM-dd'),if(equals(dayofWeek(outputs('Compose')), 6),addDays(outputs('Compose'), 2, 'yyyy-MM-dd'), outputs('Compose')))
 
as you see here: its look its working ❤️
UpgradeIT_5-1625442228490.png

 

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,828)