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

Display popup message when selected date falls within a specific weekday date range

Hi, 

 

I'm new to PA and trying to figure out how to calculate a date range, only for week days (Monday-Friday), so that specific messages popup for the user when they are completing a form.

 

I have 3 messages, each to appear on different date selections.

 

Message (1) when the user selects a date that falls within the next 4 working days - from now to 4th working day incl.

 

Message (2) when the user selects a date which is greater than 4 working days but less than 10 days, from today's date - day 5 to day 9 incl.

 

Message (3) when the user selects a date which is greater than 15 working days, from today's date - day 15 incl.

 

Here is my logic for each popup message...

#Message 1

If(
DataCardValue15 >= Weekday(Today()),true,false)

And

If(DataCardValue15 <= Weekday(Today() + 4),true,false)

 

#Message 2

If(DataCardValue15>=Weekday(Today()+5),true,false)

And

If(DataCardValue15<=Weekday(Today()+14),true,false)

 

#Messasge 3

If(DataCardValue15>=Weekday(Today()+15),true,false)

 

I'm struggling to calculate the range for the weekdays. the above doesn't seem to be working.

 

Grateful for any help/advice.

 

Thanks,

Syed

2 REPLIES 2
Highlighted
Resident Rockstar
Resident Rockstar

Re: Display popup message when selected date falls within a specific weekday date range

This is what I cam up with. It's a little overkill, and there may be an easier way, but this will expose you to some cool tricks in PowerApps. First we'll set up a loop collection so we can loop through and create a collection of days after the selected date. This can go in your App's OnStart property.

ClearCollect(Loop,
{Index:0},
{Index:1},
{Index:2},
{Index:3},
{Index:4},
{Index:5},
{Index:6},
{Index:7},
{Index:8},
{Index:9},
{Index:10},
{Index:11},
{Index:12},
{Index:13},
{Index:14},
{Index:15},
{Index:16},
{Index:17},
{Index:18},
{Index:19},
{Index:20});

Next, we'll create the actual collection we'll use to verify the number of weekdays between two dates.

Clear(DateIndexLoopResult);
ForAll(Loop,Collect(DateIndexLoopResult,{ResultIndex:Index,Weekdays:If(Weekday(DateAdd(DatePicker1.SelectedDate,Index),Saturday)<=2,0,1),Date: DateAdd(DatePicker1.SelectedDate,Index)}));

 Forall() is going to loop through our Loop collection (which is just index numbers) and build a collection of 20 days from your selected date with columns for Date and a 1 or 0 corresponding to whether it's a weekday.
Then, we'll set a variable equal to the number of weekdays between two dates. For your example, you can create 3, one for 0-4, one for 4-9, etc..

Set(WeekdaySum,Sum(Filter(DateIndexLoopResult,Date>=DatePicker1.SelectedDate,Date<=DateAdd(DatePicker1.SelectedDate,5,Days)),Weekdays))

All of this can be copied and pasted into a DatePicker's OnChange property as well.

I know this is a lot, so if you have any question, just let me know!

---
If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up.

Highlighted
Frequent Visitor

Re: Display popup message when selected date falls within a specific weekday date range

Thanks @EricLott, I'll try this out and let you know how it goes. I will have questions for sure 🙂

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (6,334)