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

Generate a list of dates derived from a range of dates

I am doing a vacation request application. On the main page the user selects a start date and an end date, what I require is that a list be generated from that range of dates without taking into account weekends and holidays.

For example: Start date: 1/28/2022 to 2/2/2028, I would expect the list to only give me: Friday, 28 January 2022 Monday, 31 January 2022 Tuesday, February 1, 2022 Wednesday, February 2, 2022. 

I referenced a similiar solution on the forum, but I still can't get the result. Clear(colDays);; With( { wStart: StarDate.SelectedDate; wEnd: EndDate.SelectedDate }; ForAll( sequence( 1 + ((DateDiff(wStart;wEnd;Days)) * 5 - ((Weekday(wStart) - Weekday(wEnd))*2)) / 7 - Switch(Weekday(wEnd);7;1;0) - Switch(Weekday(wStart);1;1;0) - CountIf( holidays; DateValue(HolidayDate) >= wStart; DateValue(HolidayDate) <= wEnd)); With( { wDay: DateAdd( wStart; value-1; days ) }; Collect( colDays; {WeekDay: wDay} ) ) ) )

 

I hope someone can support me.

Thanks in advance

2 ACCEPTED SOLUTIONS

Accepted Solutions
StalinPonnusamy
Super User
Super User

Hi @Pablo88 

 

Please try this

Clear(colDays);
ForAll(
    Sequence(
        DateDiff(
            StartDate10.SelectedDate,
            DateAdd(EndDate10.SelectedDate,1,Days),
            Days
        ),
        0,
        1
    ),
    If(
        Weekday(
            DateAdd(
                StartDate10.SelectedDate,
                Value
            )
        ) > 1 && Weekday(
            DateAdd(
                StartDate10.SelectedDate,
                Value
            )
        ) < 7,
        Collect(
            colDays,
            {
                WeekDay: DateAdd(
                    StartDate10.SelectedDate,
                    Value
                )
            }
        )
    )
)

 

Example 1

StalinPonnusamy_0-1643600767965.png

Example 2

StalinPonnusamy_1-1643600961634.png

 

View solution in original post

StalinPonnusamy
Super User
Super User

Hi @Pablo88 

 

Assume holidays are in a collection

ClearCollect(
    colHolidays1,
    {HolidayDate: DateValue("01/01/2022")},
    {HolidayDate: DateValue("02/01/2022")},
    {HolidayDate: DateValue("02/14/2022")},
    {HolidayDate: DateValue("03/15/2022")}
)

 

Leave Calculation will be

Clear(colDays);
ForAll(
    Sequence(
        DateDiff(
            StartDate10.SelectedDate,
            DateAdd(
                EndDate10.SelectedDate,
                1,
                Days
            ),
            Days
        ),
        0,
        1
    ),
    If(
        Weekday(
            DateAdd(
                StartDate10.SelectedDate,
                Value
            )
        ) > 1 && Weekday(
            DateAdd(
                StartDate10.SelectedDate,
                Value
            )
        ) < 7 && IsBlank(
            LookUp(
                colHolidays1,
                DateValue(HolidayDate) = DateAdd(
                    StartDate10.SelectedDate,
                    Value
                )
            )
        ),
        Collect(
            colDays,
            {
                WeekDay: DateAdd(
                    StartDate10.SelectedDate,
                    Value
                )
            }
        )
    )
)

 

Output (As per this example, 2/1/2022 is removed)

 

StalinPonnusamy_0-1643678505082.png

 


Thanks,
Stalin - Learn To Illuminate

View solution in original post

4 REPLIES 4
StalinPonnusamy
Super User
Super User

Hi @Pablo88 

 

Please try this

Clear(colDays);
ForAll(
    Sequence(
        DateDiff(
            StartDate10.SelectedDate,
            DateAdd(EndDate10.SelectedDate,1,Days),
            Days
        ),
        0,
        1
    ),
    If(
        Weekday(
            DateAdd(
                StartDate10.SelectedDate,
                Value
            )
        ) > 1 && Weekday(
            DateAdd(
                StartDate10.SelectedDate,
                Value
            )
        ) < 7,
        Collect(
            colDays,
            {
                WeekDay: DateAdd(
                    StartDate10.SelectedDate,
                    Value
                )
            }
        )
    )
)

 

Example 1

StalinPonnusamy_0-1643600767965.png

Example 2

StalinPonnusamy_1-1643600961634.png

 

Pablo88
Frequent Visitor

Thank you very much.

 

Work very well.

 

Can you help me, excluding the holidays please.

I have a collect with the dates.

 

StalinPonnusamy
Super User
Super User

Hi @Pablo88 

 

Assume holidays are in a collection

ClearCollect(
    colHolidays1,
    {HolidayDate: DateValue("01/01/2022")},
    {HolidayDate: DateValue("02/01/2022")},
    {HolidayDate: DateValue("02/14/2022")},
    {HolidayDate: DateValue("03/15/2022")}
)

 

Leave Calculation will be

Clear(colDays);
ForAll(
    Sequence(
        DateDiff(
            StartDate10.SelectedDate,
            DateAdd(
                EndDate10.SelectedDate,
                1,
                Days
            ),
            Days
        ),
        0,
        1
    ),
    If(
        Weekday(
            DateAdd(
                StartDate10.SelectedDate,
                Value
            )
        ) > 1 && Weekday(
            DateAdd(
                StartDate10.SelectedDate,
                Value
            )
        ) < 7 && IsBlank(
            LookUp(
                colHolidays1,
                DateValue(HolidayDate) = DateAdd(
                    StartDate10.SelectedDate,
                    Value
                )
            )
        ),
        Collect(
            colDays,
            {
                WeekDay: DateAdd(
                    StartDate10.SelectedDate,
                    Value
                )
            }
        )
    )
)

 

Output (As per this example, 2/1/2022 is removed)

 

StalinPonnusamy_0-1643678505082.png

 


Thanks,
Stalin - Learn To Illuminate

Pablo88
Frequent Visitor

Hello @StalinPonnusamy .

Thank you very much.

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,834)