Named Formulas in Power Apps
Let’s delve into the fascinating world of Named Formulas in Power Apps. These powerful constructs allow you to simplify app development, enhance maintainability, and improve performance.
Named Formulas: An Introduction
Named Formulas are inspired by an old concept from Excel—the “Name Manager.” In Excel, you can assign names to cells and refer to those names throughout your workbook. This indirection allows you to move cell references by name rather than by location. Now, this concept has made its way into Power Fx, the expressive formula language used in Power Apps.
What Are Named Formulas?
Definition:
- Named Formulas are like custom properties you create for your app.
- They encapsulate logic and calculations, much like how F = m * a in physics calculates force.
- These formulas don’t specify when or how they should be calculated; they are purely declarative recipes.
Advantages:
- Availability: The value of a Named Formula is always accessible. No timing dependencies or incorrect values.
- Interdependence: Named Formulas can refer to each other, as long as they avoid circular references.
- Parallel Calculation: They can be calculated concurrently.
- Automatic Updates: As control properties or database records change, Named Formulas automatically update their values.
Example Named Formulas
Custom properties related to user information:
UserEmail = User().Email;
UserInfo = LookUp(Users, 'Primary Email' = UserEmail);
UserTitle = UserInfo.Title;
UserPhone = Switch(
UserInfo.'Preferred Phone',
'Preferred Phone (Users)'.'Mobile Phone',
UserInfo.'Mobile Phone',
UserInfo.'Main Phone'
);
UserEmail
,UserInfo
,UserTitle
, andUserPhone
are Named Formulas.- They calculate values based on other data, and we can use them throughout the app.
- Imagine switching from the Dataverse Users table to the Office 365 connector without changing formulas elsewhere—Named Formulas make it possible!
Complex calculations
Data validation
Data transformation
Conditional formatting
Named Formula: Overdue = DateDiff(Today(), DueDate) > 0 // Use Overdue to set the background color of a label: Label2.Fill = If(Overdue, Red, LightGray)
Why Use Named Formulas?
- Always Available: No need to wait for App.OnStart or worry about timing.
- Up-to-Date: Values automatically update as data changes.
- Declarative Logic: Focus on what needs to be done, not how or when.
- Parallel Computation: Named Formulas can work together efficiently.
Remember, while Set and state variables have their place, Named Formulas offer unique benefits for app development. They’re like having your own custom properties at your disposal.
Hello thank you,
ReplyDeleteI tried this option, but it causes several problems and errors in existing apps
Could you please let me know the error message that you have received?
ReplyDelete