The right foundations changes everything
The Digital Renaissance

Power Fx: The “Native Language” of Low-Code

By Sandeep Angara

The low-code revolution is now in full effect. Businesses of all sizes and verticals are embracing tools like Microsoft Power Platform to “do it themselves,” building applications, integrations, chatbots, websites and more. The foundation of the Power Platform for low-code makers [SA1] is Power Fx, the low-code programming language that makes it all possible.

Power Fx was introduced as an open-source language in the year of 2021. It aims to minimize the number of concepts a low-coder needs to build solutions.

It’s a formula-centric language, and the result of a seven-year long research program. The origin of Power Fx lies in Microsoft Excel [SA1] formulas and in functional languages like Pascal, Mathematica and Miranda.

Some of its features include:

  • Empowers all no code, low-code, and pro code users
  • Can be used anywhere on the Power Platform
  • Asynchronous formulas that can run on-demand
  • Type checking performed indirectly

Let’s dive into few tools on Power Platform and see how Power Fx is specifically leveraged.

Power Fx formulas in Power Apps: Canvas apps

Power Apps, Power Platform’s app building tool, has two main modes: canvas apps and model-driven apps. The difference between the two modes is: Canvas apps give you more freedom in the user interface. You can start building an app from scratch using out-of-the-box components like label, text input and gallery. Model-driven apps have a data-driven approach that is built on top of Dataverse tables, which has a more streamlined UI. Power Fx has formulas for both.

Formulas are simple pre-defined functions, which provide results just by calling them or in some cases calling them with parameters required for their computation. (Here is a comprehensive list of Power Fx formulas available for Power Apps: Power Fx formula reference for Power Apps – Power Platform | Microsoft Learn.) Power Fx is not limited to these formulas; its potential can be extended by writing expressions including multiple formulas And it also has various operators to operate on data.

Power Fx formula examples for canvas apps include:

  • Now (): This formula returns the current date and time. If you would like to display the current date and time anywhere in your app, simply drag and drop a Text Label element into your app screen and provide this formula in Text property. (See Figure 1.)
  • Navigate (): Navigating between screens is typical in most any application. To enable this, developers used to write a couple of lines of code. But with Power Fx, we head to “OnSelect” property of a button and supply this formula.
  • Download (): Providing the direct URL of the file or document to the formula that users can download files.

Figure 1 Using the Now() operator. The top ribbon in the image shows the property field and an associated value field where we enter formulas or write our Power Fx Expressions.

Let’s now explore a few use cases for Power Fx formulas in Power Apps: retrieving records and writing conditions.

Retrieving Records

When we use “Gallery” in Power Apps, we come across an operator called “ThisItem”, which represents the selected record from the Gallery of records. We can retrieve various attributes of a particular record. For example: If a record contains a field or attribute called “Photo”, it can be retrieved as ThisItem.Photo, as shown in Figure 2.

Figure 2 ThisItem operator in Power Apps.

Writing Conditions

At times, we need to check on different conditions in our applications. In such cases, we have the If() formula from Power Fx shown in Figure 3. It uses a relation to check on a particular condition and takes action accordingly. For example, we use many Forms in our application that are validated for the right value to be put into the form fields.

Figure 3: If() formula in Power Apps for writing conditions.

Power Fx in Power Apps: Model-driven apps

To further the capability of a model-driven app, Microsoft brought Power Fx to the forefront.

Model driven apps have command bars that consist of different commands that drive different user actions, such as creating new records, deleting etc. Users can also define their own commands and put them on the command bar. These custom commands can be developed using Power Fx, which can manipulate the visibility of existing commands and create new commands.

Also, model-driven apps have plugins that are event handlers of Dataverse CRUD (Create, Read, Update, and Delete) events. Plugins are generally developed as custom .NET classes, but today we have a new feature called “low-code plugins” where users can define plugins with Power Fx, which helps make customizing model-driven apps easier for the citizen developer.

Power Fx in Dataverse

The provision of writing formulas is also present in Dataverse through Formula columns (see Figure 4). Earlier, calculated columns were composed in a separate interface, but now they’re integrated within a Dataverse column configuration making it easy to leverage Power Fx without being redirected to another window.

Formulas are integrated into the column settings of a Dataverse table, simplifying the calculated columns in the table itself. Whenever we have a column that is to be populated dynamically, we can use a Power Fx formula.

For example: If we have three columns namely: Price per Unit, Quantity and Total Price, we can write a formula for the calculated column “Total Price” as Price per Unit * Quantity.

Figure 4: A Formula column.

Power Fx in Power Virtual Agents

Intelligent chatbots that can answer user questions and automatically perform actions on a user’s behalf can be built on Power Platform using Power Virtual Agents (PVA).

When responding to user’s questions, you might want to perform data operations or evaluate an arithmetical expression, which is where Power Fx comes in handy as it can be used to write expressions in the authoring canvas itself. One major use case with Power Fx in PVA is output from Power Automate. The outputs from Power Automate flows may not be the right format we need; in such cases, string operations powered by our expression language (Power Fx) are extremely helpful. (See Figure 5.)

Figure 5: A Power Fx expression in PVA authoring canvas that formats user input into proper case.

And now it’s your turn!

Power Fx can be tried hands-on with Visual Studio Community edition and cloning the GitHub repository. The formulas that are supported by Power Fx can all be tried within your console.

Click this link to get started: Power Fx: Open source now available.

And don’t hesitate to contact us for advice and assistance in getting started with Power Fx.