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 / Generate a list of dat...
Power Apps
Answered

Generate a list of dates derived from a range of dates

(0) ShareShare
ReportReport
Posted on 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

Categories:
I have the same question (0)
  • Verified answer
    StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    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 Profile Picture
    10 on at

    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 at

    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 at

    Hello @StalinPonnusamy .

    Thank you very much.

     

  • jorge.daniel Profile Picture
    1,430 Super User 2024 Season 1 on at

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

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 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard