Amazing New Features of Power Apps
Named Formulas
In this Blog,
We'll discuss the amazing upcoming new feature of Microsoft Power Apps called Named Formulas. As of Sept, 2022.
Introduction to Named Formulas
A named Formula is like a global variable but its value is calculated whenever its needed and provides real time value.
It is a concept that has been in Excel for a very long time and has been brought to Power Fx now. With it you can effectively create your own properties and your own points of reuse.
It is a Preview feature and can be available to you by simply turning it on from your app settings and reloading the app after saving it.
These formulas don't sat anything about when they should be calculated or how these should be calculated. They are truly declarative.
You can declare a Named Formula in the Formula Property of the App.
Syntax
X = Value;
Where X is the name of the Declared Formula. And value is the value for the Declared Formula
The Value can be anything, It can be a sting, a boolean, a datasource, a formula, anything.
Advantages of Named Formulas
The formula's value is always available
There is no timing dependency, no that must run first before the value is set, no time in which the formula's value is incorrect Named formulas can refer to each other in any order, so long as they don't create a circular reference.
They can be calculated in parallel
The formula's value is always up to date. The formula can perform a calculation that is
dependent on control properties or database records, and as they change, the formula's value
automatically updates. You don't need to manually update the value as you do with a variable.
The formula's definition is immutable.
The definition in is the single source of truth and the value can't be changed somewhere else in the app. With variables, it is possible that some code unexpectedly changes a value, but this is not possible with named formulas. That doesn't mean a formula's value needs to be static it can change but only if dependencies change.
The formula's calculation can be deferred
Because its value it immutable, it can always be calculated when needed, which means it need not actually be calculated until it is actually needed. If the value is never used, the formula need never be calculated. Formula values that aren't used until screen2 of an app is displayed need not be calculated until screen screen2 is visible. This can dramatically improve app load time. Named formulas are declarative and provide opportunities like this for the system to optimize how and when they are computed.
Difference Between Variable and Named Formula
The Set() calculates the value whenever the Set() Function ran. It does not update the value automatically if anything changes unless you declare the variable again after any update.
The Named Formula's value is calculated in real-time whenever its needed.
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 if 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.
Upcoming Blog
In my next Blog, I'll show you how Named Formulas changed my App and made my App more efficient.
I hope you liked this Blog. Be sure to give it a thumbs up.
Comment down below for any queries or suggestions.
Comments
Post a Comment