cancel
Showing results for
Did you mean:

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,
},
varStartDate,
(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?

2 REPLIES 2
Super User

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,
},
With(
{
wDays:
Ungroup(
ForAll(
Table(
{
DoW:
wStartDate,
If(
-Value + 1,
Value - 1
)
)
}
)
),
"Value"
)
},
With(
{
wCount: CountRows(wDays) +
CountRows(
Filter(
wDays,
Weekday(DoW) = 1 || Weekday(DoW) = 7
)
)
},
wStartDate,
If(
-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

Super User

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

Announcements

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,119)