If you want a Power Apps screen to remember a small value, like a click count or whether a panel is open, the UpdateContext function is what you need. It takes a record of names and values and creates or updates those context variables, so UpdateContext({locCount: locCount + 1}) adds one to locCount.
It returns nothing and works only in behavior formulas such as OnSelect. Names you leave out keep their value.
In this tutorial, I’ll show you how to use the power apps updatecontext function with five tested examples: a click counter, a show/hide toggle, a saved SharePoint record, Patch on a record variable, and the order trap with dependent values.
Power Apps UpdateContext Function Syntax
The Power Apps UpdateContext function takes one record. Each column name becomes a context variable:
UpdateContext( { ContextVariable1: Value1 [, ContextVariable2: Value2 [, ... ] ] } )
| Parameter | Required | Type | Description |
|---|---|---|---|
ContextVariable1 | Yes | Name | The context variable to create or update. |
Value1 | Yes | Any type | Text, number, Boolean, record, table or any formula result. |
ContextVariable2: Value2, ... | No | Name + value | More variables in the same call. |
Return value: none. It only changes variables, so it works only in behavior formulas such as OnSelect, OnVisible or OnChange. New names are created, existing names are updated, and names you leave out keep their value until the app closes.
Delegation: UpdateContext queries nothing, so it has no delegation rules of its own. The formula you store follows its own rules, like the CountIf function on a big SharePoint list.
Pro Tip: Start context variable names with loc. You’ll spot them instantly, and they won’t clash with control names.
When to Use the UpdateContext Function in Power Apps
- Counting something on one screen, like clicks on a button’s OnSelect action.
- Showing or hiding a panel with a true/false flag in the Visible property.
- Remembering the SharePoint record (or Dataverse row) a user picked, so labels on the same screen can read it.
- Holding a draft record while the user edits it, before anything is saved.
If every screen needs the value, use a global variable instead; I compare both in global vs context variables in Power Apps.
Example 1: Count Button Clicks in Power Apps With a Context Variable
On my scrFnUpdateContext screen in Power Apps Studio, the first card has an Add one button and a label. Select the button, pick OnSelect in the property dropdown left of fx, and type the formula in the formula bar. To test, press Play or hold Alt and click the button.

UpdateContext({locCount: locCount + 1})
The label’s Text property shows the count:
"Clicked " & locCount & " time(s)"

How does this work?
locCount starts blank, and blank + 1 gives 1. Each click stores the current value plus one. After three clicks, the label read “Clicked 3 time(s)”.
Example 2: Show or Hide Tips With a Boolean Toggle
This is the one I use most. The button flips a true/false variable:
UpdateContext({locShowTips: !locShowTips})
The tip label’s Visible property is just locShowTips, and the button’s Text follows it:
locShowTips
If(locShowTips, "Hide tips", "Show tips")


How does this work?
The ! (Not) operator flips the value, and a blank Boolean counts as false in Power Fx. One click showed the tip, changed the button to “Hide tips” and the check label to “locShowTips: true”. The same idea works for showing or hiding a button based on a condition.
Example 3: Store a SharePoint Record in a Context Variable
Context variables can hold a whole record. I added a text input and a Load request button for the Service Requests list on our SPGuides site (620 items):
UpdateContext({locReq: LookUp('Service Requests', ID = Value(txtUcId.Text))})
The label checks for blank first, then reads the record’s columns:
If(
IsBlank(locReq),
"No request loaded",
"#" & locReq.ID & " " & locReq.Title & " | " & locReq.Status.Value & " | " & locReq.Priority.Value
)

How does this work?
LookUp returns the matching record and UpdateContext keeps all of it in locReq, so locReq.Title works anywhere on the screen. ID 12 showed “#12 Dock not charging #1011 | Closed | High”. ID 99999 left locReq blank, so the label said “No request loaded”, thanks to the IsBlank function.
Example 4: Update One Field of a Record Variable With Patch
Maria Torres reports a VPN problem, and you keep her ticket as a draft. Create draft builds the record:
UpdateContext({locTicket: {Title: "VPN drops every hour", Owner: "Maria Torres", Priority: "Normal"}})
Escalate changes only the priority:
UpdateContext({locTicket: Patch(locTicket, {Priority: "High"})})

How does this work?
You can’t assign locTicket.Priority directly in Power Apps. The Patch function merges the change into the old record and UpdateContext stores the result. The label read “VPN drops every hour | Maria Torres | Priority: High”. Nothing was saved to SharePoint.
Example 5: Avoid the Order Trap With Dependent Values
This one surprises people. One call sets a subtotal and an 8% total in the same record:
UpdateContext({locSubtotal: 250, locTotal: locSubtotal * 1.08})
Chained does the same in two calls:
UpdateContext({locSubtotal2: 250});
UpdateContext({locTotal2: locSubtotal2 * 1.08})

How does this work?
Every value in one record is calculated before any variable changes. On the first click, One call showed “$250.00 -> $0.00” because locTotal used the old blank subtotal; it reached $270.00 only on the second click. Chained showed “$250.00 -> $270.00” right away.
Pro Tip: When one variable depends on another, split them into two UpdateContext calls joined with ;.
UpdateContext vs Set
| Feature | UpdateContext | Set |
|---|---|---|
| Scope | Current screen | Whole app |
| Several variables per call | Yes | No |
| Works in App.OnStart | No | Yes |
In Power Apps, use UpdateContext for what one screen needs and the Set function for values every screen reads. To hand a value to the next screen, pass a context record when you navigate between screens.
Power Automate has no screens, so a flow uses the Initialize variable and Set variable actions instead.
Common Mistakes with the Power Apps UpdateContext Function
- Not in App.OnStart. Power Apps Studio says “‘UpdateContext’ cannot be used in a property of the app object.” Use Set there, or move it to the screen’s OnVisible (see OnStart vs OnVisible).
- Other screens can’t see it. A context variable named on another screen gives “Name isn’t valid.”
- Values survive screen changes. Reset them in OnVisible if the screen should start clean.
- Clear with Blank().
UpdateContext({locReq: Blank()})empties a variable; only the names you list change.
Wrapping Up
The Power Apps UpdateContext function stores what one screen needs: counters, toggles, picked records and drafts. Remember three rules: behavior formulas only, one screen only, and values in one record use the old values.
See all Power Apps functions for the rest of the series, and the UpdateContext function on Microsoft Learn for the official definition.
Other Power Apps functions you may find useful:

Hi! I’m Preeti Sahu, a Microsoft MVP for Power Apps. I build business apps and automations with Power Apps and Power Automate on top of SharePoint Online, and I’ve worked with SharePoint and the Power Platform for more than six years. I’m also the co-author of the book Microsoft Power Platform: A Deep Dive. My tutorials come from solutions I’ve built, from galleries and forms to approval flows, and I test every step in a real Microsoft 365 tenant. Bijay Kumar reviews each tutorial before it’s published.