cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Post Prodigy
Post Prodigy

Calculate and block data in powerapps, except

Hello guys, I'm working on an app and I need to block some dates on this app.

 

Here's the question:

 

 

The user will be blocked after six business days.

 

 

But I want to calculate when it’s a holiday, a weekend, he doesn’t count those days, would that be possible?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Hi @Gorilla_8 :

The key is to find the 6th working day after the specified date.

Firstly,We can use the following formula to exclude weekends:

 

!(Weekday(thedate) in [1,7])

 

Secondly, if you need to exclude holidays, you need a table to store all holiday days, like:

 

[Date(2020,8,4),Date(2020,8,5),Date(2020,8,6)] /*I assume these three days are holidays 2020/8/4,2020//5,2020/8/6*/

 

The code would be:

 

!(thedate in [Date(2020,8,4),Date(2020,8,5),Date(2020,8,6)])

 

 Thirdly, to find the sixth working day after a specific date, I choose to traverse the 14 days after the specified date until the sixth working day is found.

Add a button and set it's OnSelect Property to:

 

Set(startdate,Today());/*I assume the specified date is today(2020/8/3)*/
Clear(thecollection);/*thecollection is my custom collection*/
ForAll(
    [1,2,3,4,5,6,7,8,9,10,11,12,13,14],/*Traverse 14 days*/
    If(!(Weekday(DateAdd(startdate,Value,Days)) in [1,7]) /*Exclude weekends*/
    &&
    !(DateAdd(startdate,Value,Days) in [Date(2020,8,4),Date(2020,8,5),Date(2020,8,6)]),/*Exclude holiday*/
    Collect(thecollection,
    {TheDate:DateAdd(startdate,Value,Days)})));/*Store working days in thecollection*/
Set(enddate,Last(FirstN(thecollection,6)).TheDate) /*Take the sixth record in the collection,to ger the 6th business day*/

 

After performing the above operations, the sixth payday will be stored in the variable enddate.

23.gif

Best Regards,

Bof

View solution in original post

3 REPLIES 3
Community Support
Community Support

Hi @Gorilla_8 :

The key is to find the 6th working day after the specified date.

Firstly,We can use the following formula to exclude weekends:

 

!(Weekday(thedate) in [1,7])

 

Secondly, if you need to exclude holidays, you need a table to store all holiday days, like:

 

[Date(2020,8,4),Date(2020,8,5),Date(2020,8,6)] /*I assume these three days are holidays 2020/8/4,2020//5,2020/8/6*/

 

The code would be:

 

!(thedate in [Date(2020,8,4),Date(2020,8,5),Date(2020,8,6)])

 

 Thirdly, to find the sixth working day after a specific date, I choose to traverse the 14 days after the specified date until the sixth working day is found.

Add a button and set it's OnSelect Property to:

 

Set(startdate,Today());/*I assume the specified date is today(2020/8/3)*/
Clear(thecollection);/*thecollection is my custom collection*/
ForAll(
    [1,2,3,4,5,6,7,8,9,10,11,12,13,14],/*Traverse 14 days*/
    If(!(Weekday(DateAdd(startdate,Value,Days)) in [1,7]) /*Exclude weekends*/
    &&
    !(DateAdd(startdate,Value,Days) in [Date(2020,8,4),Date(2020,8,5),Date(2020,8,6)]),/*Exclude holiday*/
    Collect(thecollection,
    {TheDate:DateAdd(startdate,Value,Days)})));/*Store working days in thecollection*/
Set(enddate,Last(FirstN(thecollection,6)).TheDate) /*Take the sixth record in the collection,to ger the 6th business day*/

 

After performing the above operations, the sixth payday will be stored in the variable enddate.

23.gif

Best Regards,

Bof

View solution in original post

Ow, obrigado pela resposta rápida @v-bofeng-msft 

 

You are amazing! I will try here, and soon I will give a feedback! 

Hi @Gorilla_8 :
Has the problem been solved?
Is there anything else I can help?
If this post helps, then please consider Accept it as the solution to help others.Thanks😀
Best Regards,
Bof

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (3,487)