cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
itsmeqp
Level: Powered On

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.

 

2 REPLIES 2
Dual Super User
Dual Super User

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.
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.

 

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,793)