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 / How to create a collec...
Power Apps
Answered

How to create a collection of 7 consecutive days/dates (for a designated week) to use in a dropdown

(0) ShareShare
ReportReport
Posted on by 282

I've built a Mileage Reimbursement app. Each request submitted must ONLY be for mileage from a specific week - designated by a selected "Week Ending Date" using DatePicker1.

Then, the user clicks "Add Trips" button to navigate to the "New Trip" screen - where they choose "trip date", and input "purpose", and "trip miles". 

 

The app works great, but I had a request from the user to limit the dates available to choose as "trip date".

Currently "Trip Date" uses a date picker, which I cannot limit effectively - I need to use a dropdown for "Trip Date" to limit the choices available.

They want to allow users to add trips ONLY from the week that ends on the "Week Ending Date" entered for the parent request.

I am capturing the "Week Ending Date" entered, in a variable called 'varWkEndingDate' in the OnSelect property of the "Add Trips" button.

 

What I need is a dropdown of seven options, for the seven consecutive days/dates of the week that ends on selected "Week Ending Date" stored as 'varWkEndingDate'.

 

How do I create a collection (for a dropdown) of options for "Trip Date" that would list?...

varWkEndingDate-6
varWkEndingDate-5
varWkEndingDate-4
varWkEndingDate-3
varWkEndingDate-2
varWkEndingDate-1
varWkEndingDate

So for example, if the "Week Ending Date" captured was Sat, 12/24/22 - the dropdown would show...

Sun, 12/18/22
Mon, 12/19/22
Tue, 12/20/22
Wed, 12/21/22
Thu, 12/22/22
Fri, 12/23/22
Sat, 12/24/22

Categories:
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @rkirk2k,

     

    The button OnSelect where you create your variable, could also be used to instantly define the dropdown Items.

    Could you give the code below a try:

     

    //paste the clearcollect below the varWkEndingDate creation
    ClearCollect(
     colWeekItems,
     ForAll(
     Sequence(7),
     Text(DateAdd(
     varWkEndingDate,
     -(Value - 1),
     Days
     ), "ddd, mm/dd/yyyy")
     )
    )

     

    The dropdown would have the following code in the Items property depending on your preference:

    //Most recent date first
    colWeekItems
    
    //Oldest date first
    Sort(colWeekItems,DateValue(Value),Ascending)

     

    Keep in mind: due to the formatting "Sat, ..." the dropdown items are seen as Text values and not actual date values. If you want to save this to a date field, you will also need the DateValue() function (see Sort() function above as reference).

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

  • rkirk2k Profile Picture
    282 on at

    Thank you for the reply. When I attempt to add the "ClearCollect" function, I'm getting an error. The DateAdd function doesn't see the variable as a date. Any thoughts?

    rkirk2k_0-1672425698776.png

     

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @rkirk2k, thanks for the screenshot.

     

    Your variable is currently saving the actual control object 'DataCardValue2', not the date within that control.

    I expect that this control is probably a form date picker, so in this case the datacardvalue should be extended with the .SelectedDate property:

    Set(varWkEndDate, DataCardValue2.SelectedDate)

     

    That should do the trick.

  • rkirk2k Profile Picture
    282 on at

    Thank you Lauren. You are amazing!! This works like a charm.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 243 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 190 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard