Skip to main content

How to Use Named Formulas in Power Apps (App.Formulas)

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A named formula gives a name to a formula so you can use the name anywhere in your canvas app. It replaces the old habit of setting global variables in App.OnStart. The value is always up to date, nothing can overwrite it by accident, and Power Apps only works it out when something needs it.

Named Formula or Variable?​

Microsoft's App object reference lists why named formulas beat variables set in OnStart:

Named formulaGlobal variable set in OnStart
Always available; no timing to worry aboutBlank until OnStart has run
Updates by itself when what it depends on changesOnly changes when a formula calls Set again
Can't be changed anywhere else in the appAny Set anywhere can change it
Calculated only when neededCalculated at start, needed or not

Microsoft reports Studio load times dropping by as much as 80% in one app after moving OnStart logic into named formulas (Build large and complex canvas apps).

Use a variable only for a value the app changes, such as which record a user picked.

Prerequisites​

Step 1: Open App.Formulas​

In the tree view, select App. In the property list to the left of the formula bar, choose Formulas:

The property list of the App object open, listing BackEnabled, ConfirmExit, ConfirmExitMessage, Formulas, MinScreenHeight, MinScreenWidth, OnError, OnMessage, OnStart, SizeBreakpoints, StartScreen and Theme, with Formulas outlined in red

Step 2: Write a Named Formula​

The syntax is a name, =, a formula, and a semicolon:

App → Formulas
AppTitle = "Career Development Plan";

The formula bar with the Formulas property of App selected and the formula AppTitle = "Career Development Plan"; entered

Add more, one after another, each ending with a semicolon. They can use each other, in any order, as long as they don't go round in a circle:

App → Formulas
AppTitle = "Career Development Plan";
MyProfile = Office365Users.MyProfileV2({'$select': "id,displayName,givenName,mail,userPrincipalName,jobTitle"});
MyJobTitle = Trim(MyProfile.jobTitle);

MyJobTitle uses MyProfile; if the profile changes, the job title follows. For long formulas, select the arrow at the right of the formula bar to expand it, then Format text to lay them out neatly.

Step 3: Use It in a Control​

Type the name wherever a formula goes. The example's title label shows it:

lblTitleHS → Text
AppTitle

The preview strip under the formula bar shows the value and its type:

The formula bar with the Text property of lblTitleHS set to AppTitle, the preview strip reading AppTitle = Career Development Plan and Data type text, and the label showing Career Development Plan in the header

Change the formula in App.Formulas, and every control that uses AppTitle changes with it.

Step 4: See Every Named Formula and Its Value​

Open Variables (the {x} icon on the left) and expand Named formulas. Each one is listed with its type and current value:

The Variables pane with Global variables showing none defined yet, and Named formulas listing AppTitle (Text), IsManager (Boolean: true), MyDirectReports (Table: 1 rows), MyJobTitle (Text: Managing Director), MyManager (Record: Blank) and MyProfile (Record)

That's the quickest way to check what a formula is returning while you build.

The Rules​

  • No actions. Named formulas calculate values. Functions that do something, such as Set, Navigate or Patch, aren't allowed. Studio flags them with Behavior function in a non-behavior property; see Fixed: "Behavior Function in a Non-Behavior Property".
  • No circles. A = B; with B = A; isn't allowed.
  • Names, not prefixes. A named formula can't change, so Microsoft notes that variable prefixes like var or gbl no longer fit. Use clear PascalCase names, such as MyJobTitle.

Common Mistakes​

MistakeWhat happensDo this instead
Forgetting a semicolon between formulasA syntax errorEnd each named formula with ;
Putting Set(...) in App.FormulasBehavior function in a non-behavior propertyMake it a named formula: Name = value;
Naming formulas like variables (gblTitle)Readers think it can changeUse PascalCase names without prefixes

Troubleshooting​

SymptomLikely causeFix
A control shows nothingThe formula's value is blankCheck it under Variables → Named formulas
An error appears on the formulaA typo, missing ;, or a behavior functionHover the red underline to read the message
The value doesn't change when expectedIt depends on something that didn't changeCheck what the formula refers to

FAQ​

Do named formulas slow down the app?​

No. Microsoft notes that a named formula that isn't used costs nothing, because it's only calculated when something needs it.

Can a named formula call a connector?​

Yes. The example's MyProfile calls Office 365 Users; see How to Get the Current User's Profile and Job Title in Power Apps.

What about user-defined functions?​

App.Formulas can also hold user-defined functions and types, which take parameters. They're a separate topic; this guide covers named formulas only.

Conclusion​

Put the values your app needs in App.Formulas as Name = formula;, use the names in controls, and check their values under Variables → Named formulas. Keep actions out of them; actions belong in properties such as OnSelect.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.