Post

#PowerPlatformTip 38: 'Data Refresh'

#PowerPlatformTip 38: 'Data Refresh'

TL;DR: Don’t call Refresh() on every screen visit or inside a gallery formula (it isn’t even allowed there). Changes made by your own app via Patch() or SubmitForm() show up without it. Refresh only when someone else changed the data, and let a Boolean variable decide when that happens: after a flow, or on a timer the user can switch on and off.

💡 Challenge

Many apps call Refresh(MyDataSource) in OnVisible, after every save or on a short timer. Each call reloads the gallery’s data from the server, which costs time, network traffic and connector calls, often for data that hasn’t changed.

✅ Solution

Separate the two cases. Your own changes don’t need a refresh, because Power Apps updates the data source after Patch(), SubmitForm() or Remove(). Changes from outside (other users, a flow) do. For those, put the refresh into a behavior formula and control it with a Boolean variable.

🔧 How It’s Done

1. Remove refreshes you don’t need

🔸 Delete Refresh() after Patch(), SubmitForm() and Remove() on the same data source. The gallery shows the new values anyway.

🔸 Refresh() is a behavior function. It works in OnSelect, OnVisible or OnTimerEnd, not in a gallery’s Items.

2. Refresh after a flow changed the data

🔸 A flow writes to the data source behind the app’s back, so refresh right after it returns:

1
2
MyFlow.Run(Gallery1.Selected.ID);
Refresh(MyDataSource)

3. Let the user switch automatic refresh on and off

🔸 App.OnStart: Set(varAutoRefresh, false)

🔸 Add a Toggle with OnCheck: Set(varAutoRefresh, true) and OnUncheck: Set(varAutoRefresh, false).

🔸 Add a Timer (Visible = false) with these properties:

1
2
3
4
Duration:   60000
Repeat:     true
Start:      varAutoRefresh
OnTimerEnd: Refresh(MyDataSource)

🔸 While the toggle is off, the app doesn’t reload anything. When the user needs live data, for example on a dispatch board, the timer refreshes once per minute.

4. Refresh on demand

🔸 A refresh icon with OnSelect: Refresh(MyDataSource) covers everything else.

🎉 Result

The gallery reloads only when there is a reason: after a flow, while the user wants live data, or when the user asks for it. Your own edits still appear immediately.

🌟 Key Advantages

🔸 Fewer server calls: no reload after your own changes, no reload on every screen visit.

🔸 User control: the toggle decides whether the app polls for new data.

🔸 Valid formulas: the refresh lives in behavior properties, where Power Apps allows it.

🛠️ FAQ

1. Can I use this technique with multiple galleries in the same app?

Yes. Refresh() works per data source. Galleries on the same data source update together, galleries on different sources need their own refresh, for example in the same OnTimerEnd.

2. Does this method work with all data sources?

It works with tabular data sources such as SharePoint, Dataverse and SQL Server. Collections can’t be refreshed: rebuild them with ClearCollect().

3. Why can’t I put Refresh() into the gallery’s Items property?

Items is a data property and must not change anything. Power Apps only allows behavior functions such as Refresh() and Set() in behavior properties like OnSelect, OnVisible or OnTimerEnd.

🔸 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.

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).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.