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 Generate Dynami...
Power Apps
Unanswered

How to Generate Dynamic Year List

(0) ShareShare
ReportReport
Posted on by 93

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.

 

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    69,521 Most Valuable Professional on at

    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
  • RezaDorrani Profile Picture
    12,145 on at

    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.

     

     

  • JamesHeitmeyer Profile Picture
    16 on at

    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-apps-canvas/ba-p/346392

  • mayalghamdi Profile Picture
    40 on at

    hi! sorry to resurrect an old discussion but wanted to add my solution in case anybody else runs into the same issue. its very easy, just a sequence of the next 3 years starting now. 

     

    Sequence(3, Year(Now()), 1)

     

    generates a table so works with galleries, tables, dropdowns, etc.  let me know if it works with u!

     

  • landonjochim Profile Picture
    256 on at

    @itsmeqp - Use the Sequence function along with subtracting the start year from the current year to get your range of numbers in a Table which you can use in a dropdown, etc.

     

     

    Sequence(
     // Dynamic number of years 
     (Year(Now()) -
     // One less than the start year
     2017),
     // Start year
     2018
    )

     

     

    This will return a table like: [2018, 2019, 2020, 2021, 2022]

  • savage4618 Profile Picture
    27 on at

    To add on to this, I needed all years from 2018 until the current year, I used the following code:

    Sequence((Value(Year(Today())) - 2018) + 1, 2018, 1)

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 387

#2
timl Profile Picture

timl 340 Super User 2026 Season 1

#3
Vish WR Profile Picture

Vish WR 301

Last 30 days Overall leaderboard