Two Kinds of Variables
Power Apps has no separate variable-declaration step; a variable comes into existence the first time you assign to it. Set(varName, value) creates or updates a global variable, readable from any screen in the app, while UpdateContext({ varName: value }) creates or updates a context variable that is scoped only to the current screen and is invisible everywhere else. Both are reactive in the same way any Power Fx value is: any control bound to varName automatically re-renders when the variable's value changes, with no manual refresh.
Cricket analogy: Set is like updating the match's overall team total on the main scoreboard visible to everyone in the ground, while UpdateContext is like a fielder's private note only relevant to their own position on the field.
Global Variables with Set
Set(varCurrentUser, User()) is typically placed in the App object's OnStart property so it runs once when the app launches and the resulting variable is available on every screen thereafter. Global variables are the right tool for anything that genuinely needs app-wide visibility — the signed-in user's profile, a selected theme, a shopping cart total accumulated across multiple screens, or a flag indicating whether the app is in 'edit' versus 'view' mode. Overusing global variables for things that are really local to one screen, however, makes an app harder to reason about, since any screen could in principle be the one that changed a given global variable.
Cricket analogy: A global variable like varCurrentUser is like the team captain's identity being known and referenced by every fielder on the pitch, not just recorded once and forgotten by one player.
Local Variables with UpdateContext
UpdateContext({ varIsEditing: true, varErrorMsg: "" }) can set multiple context variables in a single call by passing a record, and unlike Set, it can only be called from within a screen's own formulas — there is no App-level equivalent. Context variables are ideal for transient, screen-local UI state: whether a details panel is expanded, which tab is active, or a temporary validation error message shown on a form before it's submitted. Because they disappear the moment the user navigates away from the screen (and are recreated fresh next time), they never leak stale state between screens the way an overused global variable can.
Cricket analogy: UpdateContext is like a fielder's private mental note about where to stand for the next ball — relevant only while they're at that position, forgotten and reset once they rotate elsewhere.
// App.OnStart — global variable available on every screen
Set(varCurrentUser, User());
Set(varTheme, "Dark");
// On a screen's OnVisible — local context variable, this screen only
UpdateContext({ varIsEditing: false, varSelectedTab: "Details" });
// A button toggling a context variable
EditButton.OnSelect = UpdateContext({ varIsEditing: !varIsEditing })
// A label reading both kinds of variable
HeaderLabel.Text = "Welcome " & varCurrentUser.FullName & " - editing: " & varIsEditingA useful rule of thumb: if a value needs to survive a screen navigation or be read from more than one screen, it must be a global variable via Set. If it's purely about this screen's own UI state, UpdateContext keeps it appropriately scoped and prevents unrelated screens from accidentally reading or resetting it.
Set and UpdateContext variables both live only in the app's runtime session — they are not persisted anywhere. Refreshing the app, or a user closing and reopening it, resets every variable back to whatever App.OnStart establishes; any value that must survive between sessions has to be written to a real data source (Dataverse, SharePoint) with Patch, not held only in a variable.
- Variables in Power Apps are created implicitly on first assignment; there's no separate declaration.
- Set(varName, value) creates a global variable readable from any screen in the app.
- UpdateContext({ varName: value }) creates a screen-scoped context variable, usable only on that screen.
- UpdateContext can set multiple variables at once via a single record argument; Set sets one at a time.
- Global variables suit app-wide state; context variables suit transient, screen-local UI state.
- Both variable types are reactive: bound controls re-render automatically when the value changes.
- Neither Set nor UpdateContext persists data across sessions — that requires writing to a real data source.
Practice what you learned
1. What is the key scoping difference between Set and UpdateContext?
2. Where is App.OnStart typically used in relation to variables?
3. How can UpdateContext set multiple variables in a single call?
4. What happens to variables created with Set or UpdateContext when the app session ends?
5. Which scenario is best suited to a context variable rather than a global variable?
Was this page helpful?
You May Also Like
Power Fx Basics
Power Fx is the Excel-like, declarative formula language that powers every property, button, and calculation in a Power Apps canvas app.
Common Functions: Patch, Filter, LookUp
Patch, Filter, and LookUp are the three functions a Power Apps maker reaches for constantly — to write data, to query many rows, and to find exactly one row.
Conditional Logic with If and Switch
If and Switch are Power Fx's two branching functions, letting formulas return different values or take different actions depending on conditions.
Working with Collections
How to create, update, and manage in-memory Collections in Power Apps for local state, offline caching, and processing data that can't be delegated to a server.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics