#PowerPlatformTip 10: 'Use all variables in PowerApps'
TL;DR: Pick the variable by its scope.
Setfor the whole app,UpdateContextfor one screen,Navigateto hand values to the next screen,Withfor a value that only lives inside one formula,Paramto read values from the app URL. For values that are always derived from others, use a named formula in App.Formulas instead of a variable.
Most apps start with Set everywhere. It works, until a value leaks into a screen where it doesn’t belong or a long formula repeats the same LookUp three times. Power Apps gives you five ways to hold a value, and each one solves a different problem.
💡 Challenge
With only Set and UpdateContext you end up with global variables for things that matter on one screen, repeated lookups inside long formulas, and no clean way to open the app on a specific record from a link.
✅ Solution
Use the full set and choose by scope and lifetime. One cheat sheet, one example each.
🔧 How It’s Done
1. The cheat sheet.
| Need | Use | Scope |
|---|---|---|
| Value used on several screens | Set(varUser, User()) | Whole app |
| State of one screen (popup open, edit mode) | UpdateContext({locShowPopup: true}) | Current screen |
| Hand a value to the next screen | Navigate(scrDetail, ScreenTransition.None, {locItem: ThisItem}) | Target screen |
| Temporary value inside one formula | With({rec: LookUp(...)}, ...) | That formula only |
| Value from the app link | Param("id") | Read-only, whole session |
| Always-derived value | App.Formulas | Whole app, recalculated automatically |
2. Set: global variables.
1
Set(varCurrentUser, LookUp(Employees, Email = User().Email))
🔸 Available on every screen. Use it for values that really are app-wide, like the current user’s record or a selected language.
3. UpdateContext: screen variables.
1
UpdateContext({locShowPopup: !locShowPopup})
🔸 Only visible on the screen where it was set. Ideal for UI state such as popups, edit modes and selected tabs.
4. Navigate with context: values for the next screen.
1
Navigate(scrDetail, ScreenTransition.Fade, {locItem: galOrders.Selected})
🔸 The third argument sets context variables on the target screen. scrDetail can use locItem without any global variable.
5. With: scoped values inside one formula.
1
2
3
4
With(
{order: LookUp(Orders, ID = galOrders.Selected.ID)},
order.Quantity * order.UnitPrice
)
🔸 The record is looked up once and used twice. The name order exists only inside this formula, so it can’t collide with anything else.
6. Param: values from the link.
🔸 Open the app with ...?id=42 appended to the web link, then read it in App.StartScreen or OnStart:
1
If(!IsBlank(Param("id")), scrDetail, scrHome)
🔸 Param always returns text. Convert it with Value(Param("id")) before comparing it with a number column.
🎉 Result
Each value lives exactly as long and as wide as it needs to. Screens stay independent, long formulas get shorter, and a link can open the app directly on the right record.
🌟 Key Advantages
🔸 Fewer side effects: screen state doesn’t leak into other screens.
🔸 Readable formulas: With names intermediate results.
🔸 Deep links: Param lets emails and Teams messages open a specific record.
🔸 Less code: named formulas replace variables that only mirror other values.
🛠️ FAQ
1. How do I decide which type of variable to use?
Ask where the value is needed. Several screens: Set. One screen: UpdateContext. The next screen: Navigate with context. One formula: With. From outside the app: Param.
2. Can I combine multiple variable types in one app?
Yes, and you should. A typical app uses Set for the user, UpdateContext for popups, With inside long formulas and Param for deep links.
3. What’s the difference between a variable and a named formula?
A variable holds a value until you set it again. A named formula in App.Formulas is recalculated automatically whenever its inputs change, so it can never be out of date.
🔗 Related Tips
🔸 The Big 5: Variables and Parameters in PowerApps - the detailed guide with more examples for Set, UpdateContext, With, Navigate and Param.
🔸 #PowerPlatformTip 43: ‘With Function’ - a deeper look at scoped record contexts with With.
Microsoft Learn: Understand canvas-app variables · With function · Navigate function
This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).