Get started with formulas in canvas apps - Power Apps (2024)

  • Article

Configure your canvas app with formulas that not only calculate values and perform other tasks (as they do in Excel) but also respond to user input (as an app requires).

  • In Excel, you build formulas that, for example, populate cells and create tables and charts.
  • In Power Apps, you build similar formulas as you configure controls instead of cells. In addition, you build formulas that apply specifically to apps instead of spreadsheets.

For example, you build a formula to determine how your app responds when users select a button, adjust a slider, or provide other input. These formulas might show a different screen, update a data source that's external to the app, or create a table that contains a subset of the data in an existing table.

You can use formulas for a wide variety of scenarios. For example, you can use your device's GPS, a map control, and a formula that uses Location.Latitude and Location.Longitude to display your current location. As you move, the map automatically tracks your location.

This article provides only an overview of working with formulas. Browse the formula reference for more details and the complete list of functions, operators, and other building blocks you can use.

Important

We're transitioning towards making the previously experimental Power Fx formula bar the default formula bar experience. The updated formula bar has better intellisense and improved error highlighting and lets you to write formulas quickly and accurately.

The updated formula bar is ON by default for new apps. For existing apps follow these steps to turn on the Power FX formula bar:

  • Open our app in Power Apps Studio, select Settings > Upcoming features > Preview > set the Power Fx formula bar toggle to ON.

Your feedback is critical as we make this updated formula bar the default experience for all apps.

Prerequisites

  • Sign up for Power Apps, and then sign in by providing the same credentials that you used to sign up.
  • Learn how to configure a control in Power Apps.

Use Power Fx formula bar

The Power FX formula bar offers a more intuitive and efficient way to write formulas for your apps. Follow these steps to use the formula bar:

  1. Open your app for editing in Power Apps Studio.
  2. Select the formula bar at the top of the screen to open it.
  3. Start typing your formula in the bar. As you type, the formula bar will provide suggestions for functions that match your input.
  4. Continue typing your formula or select the suggestions until you're done.

Show a simple value

In Excel, you can enter a specific piece of data, such as the number 42 or the phrase Hello World, by typing it into a cell. That cell will always show that data exactly as you typed it. In Power Apps, you can similarly specify a piece of data that doesn't change by setting the Text property of a label to the exact sequence of characters that you want, surrounded by double quotation marks.

  1. Create a blank canvas app.

    The formula bar sits at the top of the screen.

    Get started with formulas in canvas apps - Power Apps (1)

    1. Property list: Each control and screen has a set of properties. Use this list to select a specific property.
    2. Formula: The formula to be calculated for this property, made up of values, operators, and functions. As you type, Intellisense helps you with recommendations for formula, syntax, and errors.
    3. Selected control: In the formula bar, you can see and edit properties for the selected control or for the screen if no controls are selected.
  2. Add a Label control to the screen.

    When you add a label, the property list automatically shows the Text property, which drives what the control shows. By default, the value of this property is "Text".

  3. Set the value of the Text property to "Hello World" by typing that string, surrounded by double quotes, into the formula bar:

    Get started with formulas in canvas apps - Power Apps (2)

    The label reflects this new value as you type it. The screen may show yellow exclamation-point icons while you type. These icons indicate errors, but they'll go away when you finish entering a valid value. For example, a string without double quotation marks on both ends isn't valid.

    In Excel, you can show a number, such as 42, by typing it into a cell or by typing a formula that resolves to that number, such as =SUM(30,12). In Power Apps, you can achieve the same effect by setting the Text property of a control, such as a label, to 42 or Sum(30,12). The cell and the label will always show that number regardless of what else changes in the worksheet or the app.

    Note

    In Power Apps, you don't precede a formula with an equals sign or a plus sign as you do in Excel. The formula bar treats anything you type there as a formula by default. You also don't surround a formula with double quotation marks ("), as you did earlier to specify a string of text.

  4. In the Text property of the label, replace "Hello World" with Sum(1,2,3).

    Get started with formulas in canvas apps - Power Apps (3)

    While you type, the formula bar helps you by showing the description and the expected arguments for this function. As with the final double quotation mark in "Hello World", the screen shows red cross to indicate an error until you type the final parenthesis of this formula:

    Get started with formulas in canvas apps - Power Apps (4)

Change a value based on input

In Excel, you type =A1+A2 into a cell to show the sum of whatever values cells A1 and A2 contain. If either or both of those values change, the cell that contains the formula automatically shows the updated result.

Get started with formulas in canvas apps - Power Apps (5)

In Power Apps, you can achieve a similar result by adding controls to a screen and setting their properties. This example shows a label control named Label1 and two Text input controls, named TextInput1 and TextInput2.

Get started with formulas in canvas apps - Power Apps (6)

Regardless of what numbers you type in the text-input controls, the label always shows the sum of those numbers because its Text property is set to this formula:

TextInput1.Text + TextInput2.Text

Get started with formulas in canvas apps - Power Apps (7)

In Excel, you can use conditional-formatting formulas to show, for example, negative values in red. In Power Apps, you can use formulas to determine not only the primary value of a control but also properties such as formatting. In the next example, a formula for the Color property of the label automatically shows negative values in red. The If function should look very familiar from Excel:

If( Value(Label1.Text) < 0, Color.Red, Color.Black )

Get started with formulas in canvas apps - Power Apps (8)

Change a color based on user input

You can configure your app with formulas so that users can change your app's appearance or behavior. For example, you can create a filter to show only data that contains a string of text that the user specifies, or you can let users sort a set of data based on a certain column in the data set. In this procedure, you'll let users change the color of the screen by adjusting one or more sliders.

  1. Remove the controls from the previous procedures, or create a blank app as you did previously, and add three slider controls to it:

    Get started with formulas in canvas apps - Power Apps (9)

  2. Arrange the sliders so they don't overlap, add three labels, and configure them to show Red, Green, and Blue:

    Get started with formulas in canvas apps - Power Apps (10)

  3. Set the Max property of each slider to 255, which is the maximum value of a color component for the RGBA function.

  4. Select the screen by selecting away from any control, and then set the screen's Fill property to this formula:
    RGBA( Slider1.Value, Slider2.Value, Slider3.Value, 1 )

    As already described, you access control properties by using the . operator. Slider1.Value refers to the slider's Value property, which reflects where the user has placed the slider between the Min and Max values. As you type this formula, each control that it contains is color coded between the screen and the formula bar:

    Get started with formulas in canvas apps - Power Apps (11)

    As you type the closing parenthesis, the screen's background will change to dark gray based on the default value of each slider, which is 50. At the moment when you finish typing the formula, it's calculated and used as the value of the background fill color.

  5. Adjust the sliders, and see how your changes affect the background color by running the app.

    As each slider changes, the formula that contains the RGBA function is recalculated, which immediately changes how the screen appears.

    Get started with formulas in canvas apps - Power Apps (12)

Manage app behavior

You can use formulas not only to perform calculations and change appearance but also to take action. For example, you can set the OnSelect property of a button to a formula that includes the Navigate function. When a user selects that button, the screen that you specify in the formula appears.

You can use some functions, such as Navigate and Collect, only in behavior formulas. The formula reference calls out if you can use a function only in this context.

You can take more than one action in a behavior formula if you separate functions with a semi-colon (;). For example, you might want to update a context variable, push data to a data source, and finally navigate to another screen.

View a list of properties by category

The properties list shows properties alphabetically, but you can also view all the properties of a control, organized by category, if you select the Advanced option on the View tab from the right-side of the screen:

Get started with formulas in canvas apps - Power Apps (13)

You can edit formulas directly within this view. With the control selector at the top of the pane, you can quickly find a control to work with. And with the property search, you can quickly find a property of that control.

Initially, this view shows the most important properties. To reveal all the properties, click the down arrow at the bottom of the pane. Each control has a long list of properties that govern all aspects of the control's behavior and appearance. You can scroll through the list or search for a property by typing in the box at the top of the pane.

Formula syntax

As you type a formula in the formula bar, different syntax elements appear in different colors to improve readability and help you understand long formulas. Here is the color code list in Power Apps.

Get started with formulas in canvas apps - Power Apps (14)

See also

Use Find and Replace capability in the formula bar

Get started with formulas in canvas apps - Power Apps (2024)

FAQs

Can Power Apps do calculations? ›

A calculated column can contain values resulting from simple math operations, or conditional operations, such as greater than or if-else, and many others. You can accomplish all this by using Power Apps, no need to write code.

What is a named formula in Power Apps? ›

Named formula in Power Apps are similar to named ranges in Excel. They allow you to assign a name to a formula expression, making your app's logic easier to understand, reuse, and maintain. Named formulas can be global, accessible throughout the app, or local, scoped to a specific screen.

How to write formulas in Canvas? ›

Open Equation Editor

To open the Math Editor, click the Insert Math Equation icon [1]. You can also open the Math Editor from the Rich Content Editor menubar. Click the Insert link [2], then select the Equation option [3]. Note: To view the Insert Math Equation icon, you may need to click the Options icon [4].

What are the most important Power Apps functions? ›

Today, we review the Top 10 Power Apps Functions You Should Know (With Examples), including If, Collect, Filter, Sort, Patch, Concat, CountRows, LookUp, Max, and Min, Average (some of the most commonly used functions in PowerApps).

Is power app hard to learn? ›

Yes, Microsoft Power Platform is easy for beginners to learn. The platform provides user-friendly interfaces and offers guided learning paths and tutorials to help users get started. Additionally, there is a large community of Power Platform users who provide support and resources for beginners.

What are the disadvantages of Power Apps? ›

However, it's essential to acknowledge the cons, such as limited customization, potential costs, performance challenges, and dependency on the Microsoft ecosystem. The suitability of Power Apps hinges on your organization's specific needs and context.

What Power Apps cannot do? ›

PowerApps cannot capture digital signatures, annotated photos, audio recordings, or barcode scans.

What is the first n in Power Apps? ›

The FirstN function returns the first set of records of a table; the second argument specifies the number of records to return. The Last function returns the last record of a table.

Why we use canvas app in Power Apps? ›

Canvas apps are ideal for building task-based or role-based applications. For example, you might have a team within your customer service department that's strictly responsible for creating support tickets.

How do you trigger a flow in canvas app? ›

Add a flow to an app
  1. Create a blank canvas app with a name such as AppWithFlow.
  2. Select + (Insert) on the left-pane.
  3. Select Text input control.
  4. Select Button control.
  5. On the canvas, move the button control below the text input control.
  6. Select Action menu at the top, and then select Power Automate. ...
  7. Select FlowInApp.
Dec 16, 2022

How do you use if formula in Power Apps? ›

Microsoft Power Platform Developer | PowerApp |…
  1. Select the control that you want to apply the formula to.
  2. In the formula bar, type the following formula: If(condition, true_value, false_value)
  3. Replace 'condition' with the expression that you want to test.
May 11, 2023

What are the three types of Power Apps? ›

There are three types of Power Apps – Canvas, Model-driven, and Power Pages. The last type is now a standalone service offering more enterprise app development features.

Can you write functions in Power Apps? ›

With Power Apps user defined functions we can write a formula once and reuse the logic many times throughout an app. To do this we choose a function name, determine the inputs and their data types and write a formula to evaluate. Then we can call the function from anywhere in the app.

How do you write a power formula? ›

The formula for power in watts is given by the work and the time. The formula is P = W/t, where W is the work done in some time t.

References

Top Articles
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 5483

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.