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 / Auto Set Calendar Cont...
Power Apps
Unanswered

Auto Set Calendar Control Values based on Working Days & Public Holidays During App Start

(0) ShareShare
ReportReport
Posted on by 473

I have 2 classic calendar controls which I want to implement population of default value on app start (once) based on the scenarios below.

1) Set 'fromDate_Dp' as next working day

    - exclude weekends and dates from a collection of Public Holidays

2) Set 'toDate_Dp' as 'fromDate_Dp' + 2 working days
    - exclude weekends and dates from a collection of Public Holidays

gymcode_0-1706602025801.png

3) Sudo code for above scenarios

 

//Exclude ToDate from Weekends to find NextWorkingDay
1a. If [Weekday(Today() + 1)] Not In [1,2,3,4,5], Increment [(Today() + 1)] by 1 
 1b. If [Weekday(Today() + 1)] In [1,2,3,4,5], SetContext [NextWorkingDate]:[Today() + N]

//Get Public Holidays collection
2. ClearCollect [ServiceCalendarCol] from [ServiceCalendar.View] where [ServiceCalendar.View.Date] >= [NextWorkingDate]

//Exclude ToDate from Public Holidays, and set FromDateVal*
3a. If [NextWorkingDate] Not In [ServiceCalendarCol.Date], SetContext[FromDateVal]:[NextWorkingDate]
 3b. If [NextWorkingDate] In [ServiceCalendarCol.Date], Increment [NextWorkingDate] by 1

//Set temp_ToDateVal as 2 days after FromDateVal
4. SetContext[temp_ToDateVal]:[FromDateVal + 2]

//Exclude temp_ToDate from Weekends
5a. If [Weekday(temp_ToDateVal)] Not In [1,2,3,4,5], Increment [temp_ToDateVal] by 1
 5b. If [Weekday(temp_ToDateVal + N)] In [1,2,3,4,5], SetContext [temp_ToDateVal]:[temp_ToDateVal + N]

/Exclude temp_ToDate from Public Holidays, and set ToDateVal*
6a. If [temp_ToDateVal] Not In [ServiceCalendarCol.Date], SetContext [ToDateVal]:[temp_ToDateVal]
 6b. If [temp_ToDateVal] In [ServiceCalendarCol.Date], Increment [temp_ToDateVal] by 1

 

I'm also using classic calendar controls, so it utilizes .Value instead of .SelectedDate.
It only needs to trigger once on app start, or screen load.

I appreciate if anyone could formulate it. Thank you very much 😥
__________________________________________________________________________________________________________________________________

Below is my existing ClearCollect formula than I'm using to store all dates (exclude weekends and dates in Public Holiday collection) for reference of field names and such. (Not related to the logic of the objective of this post and scenarios above)

 

//Store selected dates
If (
 ((!IsBlank(FromDate_Dp.Value) && !IsBlank(ToDate_Dp.Value)) && (FromDate_Dp.Value <= ToDate_Dp.Value)),
 With(
 {
 //Generate a one-column table of all dates between start date & end date
 varDateRange: ForAll(
 Sequence(ToDate_Dp.Value - FromDate_Dp.Value + 1),
 FromDate_Dp.Value + Value - 1
 )
 },
 //Store Working Day Dates (Exclude weekends + Public Holidays)
 ClearCollect(
 WorkingDayDates_BetweenSelectedDates,
 Filter(
 varDateRange,
 And(
 Weekday(Value) in [ 1, 2, 3, 4, 5 ],
 Not(
 Value in Filter(
 'Service Calendars',
 'Service Calendars (Views)'.'Active Service Calendars'
 ).Date
 )
 )
 )
 );
 
 //Store Public Holiday Dates and Name Between Selected Dates
 ClearCollect(
 ServiceCalendarDateAndName_BetweenSelectedDates,
 AddColumns(
 Filter(
 varDateRange,
 Value in Filter(
 'Service Calendars',
 'Service Calendars (Views)'.'Active Service Calendars'
 ).Date
 ),
 "Name", LookUp('Service Calendars', Date = Value).Name
 )
 );
 )
);

 

Categories:
I have the same question (0)
  • ruihaolrh Profile Picture
    473 on at

    -- removed this post due to duplicated sudo code which has been updated in main post.

  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @gymcode 

     

    is the top or bottom post of yours causing issues? do we need to check top or bottom? 😉

  • ruihaolrh Profile Picture
    473 on at

    Hi @mmbr1606 , my bad! I input my existing formula as a reference for field names and such, and the logic is unrelated to the objective of this post and scenarios mentioned.

    Should I remove the existing formula to prevent confusion?
    Edit: I removed it 😁

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 150 Super User 2026 Season 2

Last 30 days Overall leaderboard