Live training: next batches coming soon. Join the waitlist:Waitlists open:Developer Training →Developer →Copilot Studio Training →Copilot Studio →

Power Apps UpdateContext Function (5 Practical Examples)

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 [, ... ] ] } )
ParameterRequiredTypeDescription
ContextVariable1YesNameThe context variable to create or update.
Value1YesAny typeText, number, Boolean, record, table or any formula result.
ContextVariable2: Value2, ...NoName + valueMore 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 formula typed in the OnSelect property of a modern button in Power Apps Studio
UpdateContext({locCount: locCount + 1})

The label’s Text property shows the count:

"Clicked " & locCount & " time(s)"
Power Apps preview showing Clicked 3 times after three button clicks

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")
Visible property of the tip label set to the locShowTips context variable
Tip label visible in preview after one click, with the button now reading Hide 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
)
SharePoint request 12 stored in a context variable and shown in a label in preview

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"})})
Record context variable after Patch changed Priority to High in preview

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})
One call versus chained UpdateContext results for a subtotal and total in preview

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

FeatureUpdateContextSet
ScopeCurrent screenWhole app
Several variables per callYesNo
Works in App.OnStartNoYes

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: