cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate II
Advocate II

How to Generate Dynamic Year List

I am wondering if there is a way to generate dynamic list within PowerApps. 

 

My scenario is if I define  a StartYear, I would like the app to generate a collection of years from StartYear to EndYear, or in my specific case, Year(Now()). I am trying to avoid manually hardcoding the years.  

 

Example:

 

StartYear = 2017

CollectionYear would contain:

  • 2017
  • 2018
  • 2019

 

then when New Years rolls around, 2020 would be included in the list.

 

3 REPLIES 3
Dual Super User III
Dual Super User III

This would be tough to do in PowerApps, but could easily be done in a Flow attached to the PowerApp.  Then return the collection to PowerApps.

 

The Flow -

  • Initalize an Array variable,
  • Build a Loop,
    • starting with the first year use the AddToTime to add a year,
    • save the year of the result,
    • if its equalto or greater than now exit the loop


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Dual Super User II
Dual Super User II

Hi @itsmeqp 

 

To do this with PowerApps 

 

First create a collection - this would be the hardcoding part

Here you can go upto 100 based on the number of years difference between todays year and the year user enters

So if you think it would be max 50 - then below array should go to 50

ClearCollect(ColNum,{Val:0},{Val:1},{Val:2},{Val:3},{Val:4},{Val:5},{Val:6},{Val:7},{Val:8},{Val:9},{Val:10})

Execute the above on App On Start

 

Then 

To get the years collection

Clear(colYears);ForAll(ColNum,If(Val<=(Year(Now())-2017),Collect(colYears,{Years:Year(Now())-Val})))

where 2017 - can be replaced by the data (numeric) that user enters

 

--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

 

 

No prob.
1. On App start set a variable to your start date. Add variable to collection.
2. Add a timer, OnStart increment your variable and add to collection.
3. Timer repeat If( var_StartYear = Year(Today()), false, true)
4. Hide Timer.
EDIT 5. Timer autoStart needs to be set as well If( var_StartYear = Year(Today()), false, true) or it will keep counting.

A variation of this found here:
https://powerusers.microsoft.com/t5/News-Announcements/How-to-do-ForEach-or-Do-while-loops-in-power-...

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (40,243)