100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Low-Code

Variables: Set and UpdateContext

Power Apps has two kinds of variables — global, created with Set, and screen-scoped context variables, created with UpdateContext — each suited to different situations.

Power Fx FormulasBeginner8 min readJul 10, 2026
Analogies

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.

powerfx
// 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: " & varIsEditing

A 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

Was this page helpful?

Topics covered

#LowCode#PowerAppsStudyNotes#MicrosoftTechnologies#VariablesSetAndUpdateContext#Variables#Set#UpdateContext#Two#StudyNotes#SkillVeris