web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Subtracting Business Days
Power Apps
Unanswered

Subtracting Business Days

(0) ShareShare
ReportReport
Posted on by 180

Hi everyone,

 

I'm working on an app to help with scheduling. Basically the goal is, knowing the desired end date of a project and a few variables, I want to be able to work back and calculate when certain steps should be met. Basically, I need to subtract business days from a value. 

I made a quick test app. Basically it has a text input with a number, and a date picker, and a text field with the following code, based off of this blog post. 

 

 

With(
 {
 varStartDate: DatePicker1.SelectedDate,
 varAddWeekdays: Value(TextInput1.Text)
 },
 DateAdd(
 varStartDate,
 Value(varAddWeekdays) + RoundDown(
 (Weekday(
 varStartDate,
 Monday
 ) + Value(varAddWeekdays) - 1) / 5,
 0
 ) * 2,
 Days
 )
)

 

 


My issue is that it works fine when I add days, but it doesn't when I need to subtract days. I've fiddled around with it but I can't quite figure it out. For example, if I have the date set to Monday, July 11th and I want to subtract 1 business day, I expect the result to be Friday July 8th, but the app returns the Sunday the 10th.

 

The only solution I can think of is to make a collection of all the dates backwards from the end date, and then use that to calculate everything but there has to be an easier way, right?

Categories:
  • WarrenBelz Profile Picture
    156,576 Most Valuable Professional on at

    Hi @RTW ,
    I felt like a bit of fried brain this morning and this one intrigued me, so try this (I have it working here in both directions)

    With(
     {
     wStartDate: DatePicker1.SelectedDate,
     wAddWeekdays: Value(TextInput1.Text)
     },
     With(
     {
     wDays: 
     Ungroup(
     ForAll(
     Sequence(Abs(wAddWeekdays)),
     Table(
     {
     DoW: 
     DateAdd(
     wStartDate,
     If(
     wAddWeekdays < 0,
     -Value + 1,
     Value - 1
     )
     )
     }
     )
     ),
     "Value"
     )
     },
     With(
     {
     wCount: CountRows(wDays) + 
     CountRows(
     Filter(
     wDays,
     Weekday(DoW) = 1 || Weekday(DoW) = 7
     )
     )
     },
     DateAdd(
     wStartDate,
     If(
     wAddWeekdays < 0,
     -wCount,
     wCount
     ),
     Days
     )
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • WarrenBelz Profile Picture
    156,576 Most Valuable Professional on at

    Hi @RTW ,

    Just checking if you got the result you were looking for on this thread. Happy to help further if not.

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 382 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 329

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard