Named Formulas in Canvas Apps: CONSTANTS AREN'T VARIABLES
Power Apps
22. Juli 2023 08:00

Named Formulas in Canvas Apps: CONSTANTS AREN'T VARIABLES

von HubSite 365 über Pragmatic Works

Citizen DeveloperPower AppsLearning Selection

Named Formulas is no longer an experimental feature! Named Formulas allow us to define constants in our Canvas Apps

Named Formulas in Canvas Apps is now a fully-fledged feature, no longer experimental. It allows us to define constants in our Canvas Apps, thereby eliminating the necessity for setting everything as variables in the OnStart property of our Apps. This provides a more streamlined and efficient approach.

Introducing Named Formulas to Power Fx

Microsoft introduces an old Excel concept, Named Formulas, to Power Fx that simplifies app initialization, reduces load time, reuses logic, and improves maintainability.

Named Formulas

In Excel, you can name any cell and refer to that name throughout the workbook. It allows you to move that cell reference by name rather than by location, and bind a name to a formula that isn't in a cell. Now, this feature is brought to Power Fx, letting you create your own properties and points of reuse.

Consider this example:

UserEmail = User().Email;
UserInfo = LookUp( Users, 'Primary Email' = User().Email );
UserTitle = UserInfo.Title;
UserPhone = Switch( UserInfo.'Preferred Phone', 
                    'Preferred Phone (Users)'.'Mobile Phone', UserInfo.'Mobile Phone',
                    UserInfo.'Main Phone' );

These formulas express how to calculate UserEmail, UserInfo, UserTitle, and UserPhone from other values.

Advantages of Named Formulas

  1. Always available: No timing dependency, no need for App.OnStart to run first before the value is set.
  2. Always up to date: The formula's value automatically updates as control properties or database records change.
  3. Immutable definition: The definition in App.Formulas is the single source of truth, and the value can't be changed somewhere else.
  4. Deferred calculation: The formula's calculation can be deferred, improving app load time.

Implications for OnStart

With the introduction of named formulas, we are addressing the second main reason for using OnStart— setting up global variables. Here's how you can translate Set calls into named formulas:

BoardSize = 70;
BoardLight = RGBA(240,217,181, 1); 
...

You can also decouple the definitions of PlayerId, AdminMode, and ReviewGo:

PlayerId = If( !IsBlank( Param( "TestPlay" ) ),
               Lower( Param( "TestPlay" ) ),
               Lower( Left( User().Email, Find( "@", User().Email )-1 ) )
           );
...

Experimental Feature

Named formulas are an experimental feature in version 3.22091. The App.Formulas property will only appear if the Named formulas experimental feature is enabled in Settings > Upcoming features > Experimental. As an experimental feature, it's recommended not to use named formulas in production apps.

What's Next

Inspired by Excel's Lambda function, a colossal step forward is planned for Power Fx— user defined functions written directly in the formula language. The plans also include making canvas components generally available, enhancing component properties, and making user defined functions easier to create and reuse. The specific dates for these features are not yet decided.

Share your feedback on how you'd use this new feature in the Power Apps experimental features community forum.

 

Exploring More About Named Formulas in Canvas Apps

Named Formulas in Canvas Apps is a remarkable innovation in application development. It permits developers to outline constants within the apps themselves negating the requirement to set up variables for every single aspect which was previously done in the OnStart property of the Apps. This translates to enhanced efficiency and a more refined procedure. The formal training offered on Microsoft products further boosts one's skill set within this domain.

Learn about Named Formulas in Canvas Apps: CONSTANTS AREN'T VARIABLES

 

Named Formulas in Canvas Apps allows us to define constants in our Apps, which eliminates the need to set everything as variables in the OnStart property. With this feature, we can now use constants to store values which will make the app more efficient and easier to use. We can also use constants to store rules used in the app, such as date, time, and text formats, which will ensure our app is consistent. Additionally, constants can also be used to store text messages or other pieces of information that will be reused by the app. Finally, constants can also be used to store data that will be used in calculations or formulas in the app.

To take advantage of this feature, we need to learn how to use the Named Formulas in our Canvas Apps. We need to understand how to create, modify, and delete constants, and how to use them in calculations and formulas. We also need to understand the different types of constants that are available to use, and how to set up conditions for them. Finally, we need to understand how to use constants in expressions and queries in our apps.

In addition to learning about Named Formulas in Canvas Apps, there are other resources available to help us on our journey. Pragmatic Works offers On-Demand Learning packages, Boot Camps, and Hackathons that can help us learn more about Microsoft Teams, Power BI, Power Apps, and Azure. The Community Plan also offers free resources to get us started.

 

More links on about Named Formulas in Canvas Apps: CONSTANTS AREN'T VARIABLES

All you need to know about named variables in Power Apps
Named formulas are introduced for a specific purpose and have certain features which are not available with variables using the Set keyword. You will continue ...
Canvas App: Incompatible variable types
Mar 29, 2020 — We can't evaluate your formula because the context variable types are incompatible with the types of values in other places in your app.”.
How to use Power Apps named formulas (experimental ...
Sep 22, 2022 — Named formulas in summary are, defined functions without parameters, that can be reused anywhere in a Canvas App.
PowerApps canvas app coding standards and guidelines - NET
As for variables, if you follow these guidelines to name your collections, you'll be able to find them very easily in the formula bar as you develop your app.34 pages
The Complete Power Apps Functions List
A cheat sheet with all 150+ Power Apps functions with links to the official documentation and also some hidden undocumented functions.
App object in Power Apps
With variables, it's possible that some code unexpectedly changes a value, but this isn't possible with named formulas. The formula's calculation can be ...
Advance Techniques for Power Apps canvas Apps
To create more than one context variable with a single formula, use a comma between the variables. UpdateContext({varCount: 1, varActive: true, varName: User().

Keywords

named formulas, canvas apps, microsoft teams, power bi, power apps, azure, on-demand learning, community plan, boot camps, hackathons