web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Collection as a variab...
Power Apps
Answered

Collection as a variable not working

(0) ShareShare
ReportReport
Posted on by 254

Hello,

 

to improve the performance of my sharepoint datasource I want to cache a table. Its just a simple table with text quotes and a index number. This table won't change so its okay to cache them. 

Table name is QuotesTable. It has Index from 0 to 37 and each row has a different quote text.

 

I use a button to change the text quotes randomly in a lable on OnSelect of the button:

 

Navigate(Screen2);;Set(vRandom;RandBetween(0;37))

 

The label text property has this:

LookUp(Shuffle(QuotesTable); Index= vRandom; Quote)

 

So every time I click on the button, screen2 appears and the text in that label is changed randomly.

 

To increase the speed of loading the app I want it to cache the whole quoteTable. So I write in the OnStart

of the App: 

Set(vQuotes;ClearCollect(CachedQuotes;QuotesTable))

 

In the label I change the property in Text to:

LookUp(Shuffle(vQuotes); Index= vRandom; Quote)

 

Now my label is always empty and I dont't know why. The ClearCollect table shows me data, but the label isn't showing any text when clicking on the button to switch the quotes. Seemingly it cannot "pull" the quotes from the variable. Is it maybe not possible to put the collect table as a global variable? Another appraoch was to put the whole ClearCollect formula into the Shuffle parenthesis, but I get a error doing this.

Hope someone knows a solution to this.

 

Thank you very much in advance. 

Best. 

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    mstrawn Profile Picture
    38 on at

    @Applicable88 

    Caching is a good idea, so you're on the right path.

    However, storing it into that variable is unnecessary. You can just do a:

    ClearCollect(CachedQuotes,QuotesTable)

    And then in your LookUp, just references the collection name like:

    LookUp(Shuffle(CachedQuotes), Index= vRandom, Quote)

     

    Give this a try and let me know!

  • Applicable88 Profile Picture
    254 on at

    @mstrawn thank you so much! The syntax is right so far and the text label reacts to the button. At the beginning I was only surprised that the table was empty. That might be the case since at the first time it got no data, since I put the Clear or ClearCollect at the App OnStart Property.

     

    One more question: 

    I just close the App completely and attached the older app version and the app with the new collection on the Android Start Menu. 

    I want to compare the app opening time to see if it really opens the app faster now.

    The old version without collection needs 24 seconds to open the app.

    You won't believe it, but the new version needs 31 seconds to open the app when PowerApps was previously complete closed.

     

    Does the "caching" only plays out its advantages once it was already open before on the phone? Does the "ClearCollect" or "Collect" needs much more time when open the first since it needs to "Collect" the table and save it locally?

    This App really only servs as a Welcome page with two buttons and a randomly switching text label to open other apps (so my colleagues only need one App attached in the startmenu to get to all apps). 

    Its a big disappointment that the user needs to wait over 20 seconds to open an app, even though its not native, 20 seconds shouldn't be normal. I want to emphasize that this table only has 30 ish rows of short quotes. 

    In both cases PowerApps itself needs already around 10 seconds to be open, until it starts to open the "actual" created app. 

     

    Any tips to improve that @mstrawn ? How long does it takes for you to open regular powerapps on your phone?

     

     

  • mstrawn Profile Picture
    38 on at

    Unfortunately, I am quite new (3-ish months) of experience with PowerApps so I am not the best with efficiency quite yet.

     

    My guess would be that it will initially take longer to open, because it is doing that caching. However, at any point on the app if you reference that collection, it will be quicker instead of going all the way to the datasource everytime.

     

    Two things though:
    1) If you are caching on the App.OnStart, keep in mind, that if you were to manipulate the data in the datasource after the app is started, when you go to reference the cache, it will not be updated, as you have only cached it once on the App.OnStart, and made changes to the data after that. You didn't mention you are doing this, so I don't think you have a concern.

    2) My PowerApp is used on Desktop, so I have no experience with the phone side. However, if you are more concerned with the app start time, maybe consider caching the data elsewhere. Potentially, you could cache it on the certain pages .OnVisible property, that way you are not doing unnecessary caching potentially. That may transfer load times to that page instead of the entire app, and may be quicker. That way, also, you solve any potential issues with #1 listed above, because every time you open the page, it re-caches.

     

    Either way caching will create some small bit of lag, it just depends where you may want it, and it may be quicker in some locations over others. Try doing it at different spots, and seeing what you find!

  • Applicable88 Profile Picture
    254 on at

    @mstrawn , thanks mate. I put it on the button for switching the pages. It did saved me 5 seconds. I hope I can find other ways to improve the opening speed of the app. It runs smoothly ones opened, thats not the problem tho.

    Cheers.

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard