Showing results for 
Search instead for 
Did you mean: 
Resolver II
Resolver II

Dynamic Variables

Is it possible to have a dynamic variable that is dependent on the nth record it is in?


To explain:


I have a Gallery that shows records, each record has a different "Added Date and time".


I want to create a countdown against each record which displays the minutes and seconds left until 15 minutes after is was added.


i.e record 1 was added at 12:00 , current time is 12:05 , countdown would show 00:10:00 (Ten minutes left)


To generate the values needed to create the countdowns I have a timer with the duration of 1000 ms (1 sec) that repeats and does the below ontimerend (it works out the difference between when the record was added and now in ms)


UpdateContext( { Countdowns:{ Countdown1 : DateDiff(DateTimeValue(Text(First('DATASOURCE]'.Date_x0020_Added).Date_x0020_Added)),Now(),Milliseconds),Countdown2 : DateDiff(DateTimeValue(Text(Last(FirstN('DATASOURCE]'.Date_x0020_Added,2)).Date_x0020_Added)),Now(),Milliseconds) }} )

This creates the variable "countdowns" with both countdown1 and countdown2 retrieving their values from selected (1st & 2nd)  records, achieved by using the "First" and a "Last(FirstN" functions to select the correct record. This will be expanded for the 3rd 4th etc when I work out the below issue.


So this works well , however i'm now not sure how to call the variables in the respective record.


What I want to say in the label text property in each record (that will be the countdown) is "If i'm the first record in the gallery my text property should be Countdown1" and "If i'm the Second record in the gallery my text property should be Countdown2". 


So I need to call the correct variable dependant on which record "I" am.


I really hope this makes sense.


Alternatively if you can think of a different way of achieving this requirement please let me know.


To be honest this is were a foreach function would come in handy.


As always any help would be greatly appreciated!



Community Support
Community Support

Hi @SamPhillips,


Please consider take use of AddColumns() function to create a collection with a CountDown column added to the original data source, better with the Primary Key Renamed to another value, for example, rename the ID field to CID.

So the structure should be:

ClearCollect(Temp, AddColumns(RenameColumns(DataSource, "ID", "CID"), "CountDown",CountDownFormula ))

Once collection is generated, we could take use of the ID and the CID to lookup the CountDown value for each record.


For example:

CountDownLabel within the Gallery: 

Lookup(Temp, CID=ThisItem.ID, CounfDown)

Function reference:

AddColumns in PowerApps

Lookup in PowerApps


Please post back if you need any further help on this.




Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,955)