I am trying to skip weekends and federal holidays when selecting from a date picker it will auto project the next date into the date picker ahead of it skipping weekends and holidays it currently does not skip weekends, I am using the default date control in the datepicker thats ahead of this one
With(
{
baseDate: Planning_STEP01DataCardValue.SelectedDate, // Starting point
varHoliday: FEDholiday_list_2024_2030.HolyDate, // List of holidays
daysToAdd: Step2_Duration, // Number of workdays to add
currentDate: Planning_STEP01DataCardValue.SelectedDate, // Initialize current date as base date
workdaysAdded: 0 // Initialize workdays counter
},
// Loop until we add the required number of workdays
While(
workdaysAdded < daysToAdd,
// Check if the current date is a weekend (Saturday=7, Sunday=1) or holiday
If(
Weekday(currentDate, StartOfWeek.Monday) in [7, 1] || currentDate in varHoliday,
// If weekend or holiday, move to the next day
Set(currentDate, DateAdd(currentDate, 1, TimeUnit.Days)),
// If it's a valid workday, increment the counter
Set(workdaysAdded, workdaysAdded + 1),
// Always move to the next day
Set(currentDate, DateAdd(currentDate, 1, TimeUnit.Days))
)
),
// Return the final ProjectedDate after loop ends
currentDate
)