#PowerPlatformTip 38: 'Data Refresh'
TL;DR: Control gallery updates with a Boolean variable so you Refresh only when needed instead of reloading all data every time.
💡 Challenge
Maintaining up-to-date data in PowerApps galleries is crucial for user experience. However, relying solely on the Refresh function reloads all data and can impact performance.
✅ Solution
Use a Boolean variable to trigger selective gallery data refresh, avoiding full data reloads and enhancing performance.
🔧 How It’s Done
Here’s how to do it:
-
Create a Boolean variable to control refresh. 🔸 Example:
Set(varRefreshGallery, false)in the App’s OnStart.🔸 This variable determines when the gallery should update.
-
Toggle the variable when refresh is needed. 🔸 Add a button or icon with
OnSelect: Set(varRefreshGallery, true).🔸 This signals the gallery to refresh its data source.
-
Use the variable in the gallery’s Items property. 🔸 Example:
1 2 3 4 5 6
If( varRefreshGallery, Refresh(MyDataSource); Set(varRefreshGallery, false) ); MyDataSource🔸 After the refresh, reset the variable to false.
🎉 Result
You achieve a more responsive and efficient app, refreshing only when needed and improving the user experience.
🌟 Key Advantages
🔸 Improved performance by avoiding unnecessary full data reloads.
🔸 Enhanced user experience with faster, targeted updates.
🔸 Greater control over when and how data is refreshed in your app.
🔗 Related Tips
🔸 Power Apps: Refresh Is Killing Your App Performance - the broader problem this Boolean-variable pattern solves.
🔸 #PowerPlatformTip 81: ‘Fast DataSource Updates’ - more patterns for keeping large data sets fast to update and reload.
🛠️ FAQ
1. Can I use this technique with multiple galleries in the same app?
Yes, you can create separate Boolean variables for each gallery to control their refresh independently.
2. Does this method work with all data sources?
This technique works with most PowerApps data sources, including SharePoint, Dataverse, and SQL Server connectors.
3. How does this compare to using the Refresh() function directly?
Using a Boolean variable gives you more control over when refreshes occur and can prevent unnecessary API calls compared to direct Refresh() usage.
This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).