cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SamPhillips
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!

 

Thanks!

1 REPLY 1
v-micsh-msft
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.

 

Regards,

Michael

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

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (3,055)