SOLVED

Power Automate: IF date falls on a weekend THEN subtract 2 days (SharePoint List)

Copper Contributor

Good day,

 

I've created a list called Recurring Finance Tasks:

 

RobinProctor_1-1685008694144.png

 

I do not want tasks to fall on a weekend.

How can I build a flow that checks the date daily and subtracts two days (putting the date in the previous week) if the date falls on a weekend?

 

RobinProctor_4-1685009136735.png

RobinProctor_0-1685009832087.png

 

Condition expressions:

  • and(not(equals(item()?['Next Date'], null)), equals(formatDateTime(item()?['Next Date'], 'dddd'), 'Saturday'))
  • and(not(equals(item()?['Next Date'], null)), equals(formatDateTime(item()?['Next Date'], 'dddd'), 'Sunday'))

Next Date expressions:

  • addDays(item()?['Next Date'], -2, 'dd-MM-yyyy')

I've tried so many different approaches and keep failing, I'm not a coder so please excuse any mistakes I've made via my endless Googling.

 

Any help would be hugely appreciated!

 

Regards,

Robin

2 Replies
best response confirmed by RobinProctor (Copper Contributor)
Solution

@RobinProctor you seem to be slightly over-complicating it. In my example below there is the Review Date column, a calculated column for Weekday using the formula 

=IF(ISBLANK([Review Date]),"",TEXT([Review Date],"dddd"))

 

The WeekdayChecked column is a choice column with the choices No and Yes and a default value of No. The items that will be changed are Almeria (Sunday), Lubrin (Sunday), Mojacar (Saturday) and Villaricos (Sunday).
0-SPList.png

 

After the recurrence schedule trigger the first action is to get the items but I've added a filter query of WeekdayChecked eq 'No' so it's not having to check every item in the list every day.

 

1-Flow.png

 

The condition just needs to Weekday is equal to Saturday Or Weekday is equal to Sunday.

2-Flow.png

 

In the red if no channel add an update item action and change the WeekdayChecked Value column to Yes.

 

3-Flow.png

 

In the green if yes channel add 3 Compose actions. In the first one select Weekday from the dynamic content box (just there as a check really).

 

In the second one which I've renamed to ComposeReviewDate select Review Date from the dynamic content box.

 

In the third one which I've renamed to ComposeMinus2 add the expression 
addDays(outputs('ComposeReviewDate'),-2)

 

4-Flow.png

 

Finally, add an update item action and for the Review Date select the outputs of ComposeMinus2 and change the WeekdayChecked Value field to Yes.

5-Flow.png

 

After the flow runs the 4 items that we expected to be changed to 2 days earlier have been as shown below. Almeria, Lubrin and Villaricos now have a review date 2 days earlier on the Friday and Mojacar on the Thursday.

6-SPList.png

 

Hope that helps.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

 

@RobElliott thank you so much! You're a champ! My issues are now solved - headache and automation.

 

RobinProctor_0-1685022489425.png

 

RobinProctor_1-1685022559720.png

 

1 best response

Accepted Solutions
best response confirmed by RobinProctor (Copper Contributor)
Solution

@RobinProctor you seem to be slightly over-complicating it. In my example below there is the Review Date column, a calculated column for Weekday using the formula 

=IF(ISBLANK([Review Date]),"",TEXT([Review Date],"dddd"))

 

The WeekdayChecked column is a choice column with the choices No and Yes and a default value of No. The items that will be changed are Almeria (Sunday), Lubrin (Sunday), Mojacar (Saturday) and Villaricos (Sunday).
0-SPList.png

 

After the recurrence schedule trigger the first action is to get the items but I've added a filter query of WeekdayChecked eq 'No' so it's not having to check every item in the list every day.

 

1-Flow.png

 

The condition just needs to Weekday is equal to Saturday Or Weekday is equal to Sunday.

2-Flow.png

 

In the red if no channel add an update item action and change the WeekdayChecked Value column to Yes.

 

3-Flow.png

 

In the green if yes channel add 3 Compose actions. In the first one select Weekday from the dynamic content box (just there as a check really).

 

In the second one which I've renamed to ComposeReviewDate select Review Date from the dynamic content box.

 

In the third one which I've renamed to ComposeMinus2 add the expression 
addDays(outputs('ComposeReviewDate'),-2)

 

4-Flow.png

 

Finally, add an update item action and for the Review Date select the outputs of ComposeMinus2 and change the WeekdayChecked Value field to Yes.

5-Flow.png

 

After the flow runs the 4 items that we expected to be changed to 2 days earlier have been as shown below. Almeria, Lubrin and Villaricos now have a review date 2 days earlier on the Friday and Mojacar on the Thursday.

6-SPList.png

 

Hope that helps.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

 

View solution in original post