cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
EdouardVH
Frequent Visitor

Define an end date based on a number of working days

Hello,

 

I am working on a powerapps application and I have to set an end / close date according to a number of working days.


Ex: the user selects a date and I add 20 working days to this date in order to define the closing date.

 

The other particularity is that I have to include vacation days present in a SharePoint list.

 

I have found some posts that allow me to set a number of working days between a start date and an end date.

 

do you have an idea ?

 

Thanks 

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User
Super User

Hi @EdouardVH 

I have a post here that describes how to add working days to a date, and to exclude public holidays.

http://powerappsguide.com/blog/post/formulas-how-to-cope-with-weekends-public-holidays-in-date-calcu...

 

The formula looks like this:

With({ startDate:DateValue("2021-01-18"),
       daysToAdd: 7
      },
      DateAdd(startDate, daysToAdd) + 
      RoundDown(daysToAdd/5, 0)*2 +
      Switch(Weekday(startDate, StartOfWeek.Monday),
             5,If(Mod(daysToAdd, 5)>0,2,0),
             4,If(Mod(daysToAdd, 5)>1,2,0),
             3,If(Mod(daysToAdd, 5)>2,2,0),
             2,If(Mod(daysToAdd, 5)>3,2,0),
             1,If(Mod(daysToAdd, 5)>4,2,0)
      ) +
      CountIf(colHolidays, DateValue(Result) >= startDate, DateValue(Result) <= startDate)
)

Here, colHolidays is a collection of public holidays. You would replace this with a reference to your SharePoint list.

View solution in original post

2 REPLIES 2
timl
Super User
Super User

Hi @EdouardVH 

I have a post here that describes how to add working days to a date, and to exclude public holidays.

http://powerappsguide.com/blog/post/formulas-how-to-cope-with-weekends-public-holidays-in-date-calcu...

 

The formula looks like this:

With({ startDate:DateValue("2021-01-18"),
       daysToAdd: 7
      },
      DateAdd(startDate, daysToAdd) + 
      RoundDown(daysToAdd/5, 0)*2 +
      Switch(Weekday(startDate, StartOfWeek.Monday),
             5,If(Mod(daysToAdd, 5)>0,2,0),
             4,If(Mod(daysToAdd, 5)>1,2,0),
             3,If(Mod(daysToAdd, 5)>2,2,0),
             2,If(Mod(daysToAdd, 5)>3,2,0),
             1,If(Mod(daysToAdd, 5)>4,2,0)
      ) +
      CountIf(colHolidays, DateValue(Result) >= startDate, DateValue(Result) <= startDate)
)

Here, colHolidays is a collection of public holidays. You would replace this with a reference to your SharePoint list.

View solution in original post

EdouardVH
Frequent Visitor

hi @timl , 

 

Thanks you for your help. it works perfectly.

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
Top Kudoed Authors
Users online (2,745)