Power Fx named formulas to ease development and improve performance
Important
This content is archived and is not being updated. For the latest documentation, go to What's new in Power Apps?. For the latest release plans, go to Dynamics 365 and Microsoft Power Platform release plans.
Important
Some of the functionality described in this release plan has not been released. Delivery timelines may change and projected functionality may not be released (see Microsoft policy). Learn more: What's new and planned
Enabled for | Public preview | Early access | General availability |
---|---|---|---|
Admins, makers, marketers, or analysts, automatically | Sep 11, 2022 | - | To be announced |
Business value
This feature simplifies app writing as state variables don't need to be manually initialized and maintained. This capability helps apps perform better as the system is free to optimize, defer loading data and calculating values until needed.
Feature details
Today, makers must initialize global variables and collections in App.OnStart
or Screen.OnVisible
. Since these formulas are imperative, it limits the optimizations that Power Apps can apply to defer and rearrange work to reduce the app load time.
As an example of a better way, Microsoft Excel supports the naming of formulas with the Name Manager, making formulas reusable across the spreadsheet. We're going to adopt this idea for Power Fx.
Instead of writing Set( X, Last(Accounts) )
, you'll be able to write X = Last(Accounts)
. It's a subtle yet powerful change. In this example, when using Set()
, X
is only valid after Set()
has been called. And X
may become invalid if Accounts
is changed without Set()
being called again. X
could also be set in some other part of the app unintentionally. Furthermore, if you intend to capture X
at that moment (before it changes), and Power Fx can't optimize it, you'd have to retrieve Accounts
each time when calling Set()
.
The named formula approach results in X
always being set and always being up to date with changes in Accounts
. The named formula sets up a dependency relationship between X
and Accounts
, much as Excel would have between spreadsheet cells. There's only one source of truth—if you want to understand why X
has the value it has. And that is—you only need to look at the formula that defines it, nothing else can modify it. Power Fx optimizations are possible because X
need not be evaluated unless it's used, and it can always be recalculated at that moment from the current state of Accounts
.
Named formula can be used for simple values too. Often, App.OnStart
will set up theme colors for the app. Instead of writing Set( BackgroundColor, Color.Gray )
, you can now write BackgroundColor = Color.Gray
. With the named formula, you don't need to execute Set()
. No state variable is involved, and BackgroundColor
is immutable and won't change. This feature eliminates a source of confusion and possible maker errors—even for simple use cases.