Skip to main content
Community site session details

Community site session details

Session Id : BvxPNcBH+bl13BTaGQzqVk
Power Apps - Building Power Apps
Answered

Generate a list of dates derived from a range of dates

Like (0) ShareShare
ReportReport
Posted on 28 Jan 2022 21:50:39 by 10

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

  • jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on 19 Feb 2023 at 10:38:50
    Re: Generate a list of dates derived from a range of dates

    Great, just what I was looking for. Thank you for sharing.

  • Pablo88 Profile Picture
    10 on 01 Feb 2022 at 15:02:43
    Re: Generate a list of dates derived from a range of dates

    Hello @StalinPonnusamy .

    Thank you very much.

     

  • Verified answer
    StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on 01 Feb 2022 at 01:23:13
    Re: Generate a list of dates derived from a range of dates

    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 Profile Picture
    10 on 31 Jan 2022 at 22:48:35
    Re: Generate a list of dates derived from a range of dates

    Thank you very much.

     

    Work very well.

     

    Can you help me, excluding the holidays please.

    I have a collect with the dates.

     

  • Verified answer
    StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on 31 Jan 2022 at 03:49:42
    Re: Generate a list of dates derived from a range of dates

    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

     

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete