cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Dual Super User II
Dual Super User II

Re: How to Generate Dynamic Year List

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.
Highlighted
Dual Super User
Dual Super User

Re: How to Generate Dynamic Year List

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.

 

 

Highlighted
Regular Visitor

Re: How to Generate Dynamic Year List

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
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (1,803)