Avoiding Unnecessary Recalculation of Expressions in Power Apps
Introduction
When developing Power Apps, inefficient calculations can slow down app performance, cause lag, and increase processing time. This happens when Power Apps recalculates expressions repeatedly, even when the values havenβt changed. By optimizing how and when calculations occur, you can improve performance and create a faster, more responsive app.
This guide explains why unnecessary recalculations happen, and provides step-by-step strategies to avoid them.
1. Why Do Unnecessary Recalculations Happen?
Power Apps automatically recalculates expressions whenever there is a change in dependencies. This includes:
π¨ Using the same calculation multiple times in different places.
π¨ Referencing dynamic controls (like sliders or text inputs) in calculations.
π¨ Performing LookUp or Filter operations repeatedly.
π¨ Using complex calculations in gallery items, OnVisible, or OnStart.
Example of Inefficient Calculation
If(
LookUp(Orders, ID = SelectedOrderID).Status = "Completed",
"Delivered",
"Pending"
)
π¨ Problem: If this is used multiple times, Power Apps runs the LookUp() function each time instead of reusing the result.
β Solution: Store the result in a variable instead of recalculating it each time.
2. How to Avoid Unnecessary Recalculations
2.1 Use Variables for Static Values
Instead of recalculating an expression each time itβs needed, store it in a variable using Set()
or UpdateContext()
.
Before (Inefficient Calculation in Multiple Places)
If(User().Email = "admin@company.com", true, false)
π¨ Problem: If this expression appears in multiple controls, Power Apps recalculates it every time.
After (Optimized with a Variable in OnStart)
Set(IsAdmin, User().Email = "admin@company.com")
β
Now, use IsAdmin
throughout the app instead of recalculating it.
2.2 Use Collections Instead of Multiple LookUps
If you’re fetching data multiple times using LookUp()
, store it in a collection instead.
Before (Repeated LookUp in Multiple Controls)
LookUp(Users, Email = User().Email).Role
π¨ Problem: Runs the LookUp() function each time it is used.
After (Optimized by Storing in a Collection on Start)
ClearCollect(UserData, Filter(Users, Email = User().Email));
Set(UserRole, First(UserData).Role)
β
Now, use UserRole
instead of LookUp() in multiple places.
2.3 Avoid Recalculating Dynamic Controls (Like Sliders, Dropdowns, or Text Inputs)
If you reference a control directly in a formula, it recalculates every time the control changes.
Before (Inefficient Formula in Multiple Places)
Slider1.Value * 10
π¨ Problem: Every time the slider moves, all calculations that use it will be recalculated.
After (Optimized by Storing in a Variable on Change)
Slider1.OnChange = Set(SliderValue, Slider1.Value * 10)
β
Now, use SliderValue
instead of Slider1.Value * 10
throughout the app.
2.4 Use With() to Store Temporary Values Instead of Recalculating
With()
allows you to store temporary values within a single formula without creating global variables.
Before (Repeated Calculation in a Single Formula)
If(
LookUp(Orders, ID = SelectedOrderID).Status = "Completed",
"Delivered",
"Pending"
)
π¨ Problem: LookUp()
runs twice.
After (Optimized Using With())
With(
{ OrderStatus: LookUp(Orders, ID = SelectedOrderID).Status },
If(OrderStatus = "Completed", "Delivered", "Pending")
)
β
Now, LookUp()
runs only once, and OrderStatus
is reused.
2.5 Optimize Formulas in Galleries
Galleries recalculate formulas for each row, which can slow down performance.
Before (Inefficient LookUp in a Gallery)
Text = LookUp(Customers, ID = ThisItem.CustomerID).Name
π¨ Problem: Runs LookUp()
for every row in the gallery.
After (Optimized by Preloading Data in a Collection)
ClearCollect(CustomerList, Customers)
Text = LookUp(CustomerList, ID = ThisItem.CustomerID).Name
β Now, LookUp() is much faster because it queries a local collection instead of an external data source.
2.6 Move Calculations to OnStart or OnVisible When Possible
Instead of recalculating values every time the screen is used, store them on app start or when the screen is loaded.
Example (Before: Inefficient Calculation in a Control’s Property)
Filter(Orders, Status = "Pending")
π¨ Problem: This runs every time the control refreshes.
Example (After: Optimized by Storing in OnVisible)
Screen.OnVisible = ClearCollect(PendingOrders, Filter(Orders, Status = "Pending"))
β
Now, use PendingOrders
instead of filtering the entire dataset each time.
3. Best Practices to Avoid Unnecessary Recalculations
β
Use Variables (Set()
, UpdateContext()
) for static or frequently used values.
β
Use With()
to store temporary values inside a single formula instead of re-evaluating expressions.
β
Cache data using ClearCollect()
to avoid repeated API or database calls.
β
Minimize LookUps in galleries by preloading the dataset.
β
Move calculations to OnStart
or OnVisible
when possible.
β
Avoid referencing dynamic controls (Slider
, Dropdown
, TextInput
) directly in formulas.
4. Conclusion
Avoiding unnecessary recalculations in Power Apps boosts performance, speeds up load times, and improves user experience. By storing values in variables, using collections for lookups, and optimizing gallery formulas, you can ensure your app runs efficiently.
Would you like specific optimizations for SharePoint, SQL, or Dataverse?