PowerApps if statement with examples

In this PowerApps Tutorial, We will discuss what is PowerApps If function or PowerApps if condition, What is PowerApps Switch function and it’s all syntaxes. Also, We will cover these below topics those are related to Powerapps if statement as:

  • Powerapps if statement examples
  • Powerapps if statement multiple conditions
  • Powerapps if statement multiple actions
  • Powerapps if statement contains text
  • Powerapps if statement dropdown value
  • Powerapps visible if statement
  • Powerapps nested if
  • Powerapps OnSelect if statement
  • Powerapps conditional formatting
  • Powerapps if statement with or
  • Powerapps if statement in patch
  • Powerapps if statement with toggle
  • Powerapps if statement do nothing

PowerApps If and Switch Function

  • Powerapps if function specifies whether one or more conditions in a set is true. that means, if the result is found as true, then the corresponding value is returned. If no result is found, then the default value is returned.
  • Powerapps Switch function specifies whether the result matches any value in a set or not. If the match is found, then the corresponding value is returned. If there is no match found, then a default value is returned.
  • Powerapps If and Switch function both are mostly similar. But as per your requirement, you need to choose the specific function.
  • You can use the If function to execute a single condition. You may know the most common syntax for the If function is: If( Condition, ThenResult, DefaultResult ) that defines as the “if…then…else…” pattern.
  • You can use the If function to execute multiple conditions. You can specify multiple conditions without having to nest if formulas.
  • You can use the Switch function to execute a single condition against the multiple possible matches. To repeat the formula for each possible match, also you can use the If function.
  • Blank is returned if no conditions are true, no matches are found, and you don’t specify a default result.

Powerapps If Function Syntaxes:

Below represents Powerapps If function syntaxes:

Syntax 1:

If( Condition, ThenResult [, DefaultResult ] )

Syntax 2:

If( Condition1, ThenResult1 [, Condition2, ThenResult2, ... [ , DefaultResult ] ] )

Where,

  • Condition(s) = This is required. Formula(s) to test for true. Such formulas commonly contain comparison operators (such as <, >, and =) and test functions such as IsBlank and IsEmpty.
  • ThenResult(s) = This is also required. The corresponding value to return for a condition that evaluates to true.
  • DefaultResult = This is an optional. The value to return if no condition evaluates to true. If you don’t specify this argument, a blank is returned.

Powerapps Switch Function Syntax:

Switch( Formula, Match1, Result1 [, Match2, Result2, ... [, DefaultResult ] ] )
  • Formula = This is required that specifies the formula to evaluate for matches. This formula is evaluated only once.
  • Match(s) = This is also required that defines values to compare with the result from Formula. If an exact match is found, the corresponding result is returned.
  • Result(s) = This is required where the corresponding value to return when an exact match is found.
  • DefaultResult = This is optional. If an exact match isn’t found, this value is returned. If you don’t specify this argument, a blank is returned.

Example:

In this below example, I have a Slider control that has a value of 30. Based upon this slider value, We will see the various formulas and its results of If statement.

Formula Description Result
If( Slider1.Value = 30, “Result1” ) The condition is true, and the corresponding result is returned. “Result1”
If( Slider1.Value = 30, “Result1”, “Result2” ) The condition is true, and the corresponding result is returned. “Result1”
If( Slider1.Value > 2000, “Result1” ) The condition is false, and no DefaultResult was provided. Blank
If( Slider1.Value > 2000, “Result1”, “Result2” ) The condition is false, a DefaultResult was provided, and it’s returned. “Result2”
If( Slider1.Value = 30, “Result1”, Slider1.Value > 0, “Result2” ) The first condition is true, and the corresponding result is returned. The second condition is also true, but it isn’t evaluated because it appears later in the argument list than a condition that evaluates to true. “Result1”
If( IsBlank( Slider1.Value ), “Result1”, IsNumeric( Slider1.Value ), “Result2” ) The first condition is false because the slider isn’t blank. The second condition is true because the slider’s value is a number, and the corresponding result is returned. “Result2”
If( Slider1.Value > 2000, “Result1”, Slider1.Value > 60, “Result2”, “Result3”) Both the first and second conditions are false, a DefaultResult was provided, and it’s returned. “Result3”
Switch( Slider1.Value, 30, “Result1” ) The slider’s value matches the first value to be checked, and the corresponding result is returned. “Result1”
Switch( Slider1.Value, 20, “Result1”, 25, “Result2”, 30, “Result3” ) The slider’s value matches the third value to be checked, and the corresponding result is returned. “Result3”
Switch( Slider1.Value, 20, “Result1”, 10, “Result2”, 0, “Result3”, “DefaultResult” ) The slider’s value doesn’t match any value to be checked. A DefaultResult was provided, so it’s returned. “DefaultResult”

Powerapps if statement examples

Here we will discuss a simple scenario of PowerApps if Statement (step by step).

Step-1:

In the Powerapps screen, Insert a Text input control and modify its name as txtInput (optional).

Step-2:

In the Text input control, enter a value as 35.

Step-3:

Insert a Label input control and apply this below formula on its Text property as:

Text = If(
    Value(TxtInput.Text) < 30,
    "Order MANY more!",
    Value(TxtInput.Text) < 50,
    "Order more!",
    TxtInput.Text
)

Where,

TxtInput.Text = Text input control name

You can refer the below screenshot.

  • On the screen, you can see the Label input control shows Order more! because the value of Text1 is more than 30 but less than 50.
Powerapps if statement examples
Powerapps if statement

Step-4:

Similarly, in the text input control, enter a value 25. You can see the Label input control shows Order MANY more! because the value of Text1 is less than 30.

Powerapps if statement example
Powerapps if statement example

Step-5:

Now, enter a value of 50 in the text input control. The Label input control displays the value that you typed because it’s more than 30.

Powerapps if statement
Powerapps if statement

Powerapps if statement multiple conditions

  • Here we will see how we can use multiple if statements in a simple way. As you know, for one condition, you can apply the below formula that is easy for understanding.
If(<condition 1>, <result if true>, .... , <default value>)
  • Similarly, suppose you want to apply two or multiple conditions in one If statement, then you can use the && operation instead of nested If statements.
  • For example,
    • If(IsToday(joiningday) && IsToday(joiningparty), “Welcome to our company” , DateDiff(Today(),joiningday,Days) & ” day(s) to joiningday”) instead of If(IsToday(joiningday), If(IsToday(joiningparty), “Welcome to our company”)
  • In this above formula, they both return the same value but the second If statement is more complex than the first If statement.
  • Another most important thing you should know is, You can only nest 50 If statements. If you reach this limit, then you’re overcomplicating the overall formula.

Powerapps if statement multiple actions

  • Suppose you want to chain multiple functions in a true case of an if statement by using “;” as a delimiter. As on the locale, “;” is the default delimiter. Then the question is, which delimiter you can use to get multiple statements executed for the if true branch.
  • To answer this question is, If you will use a “,” between arguments in your formula, then “;” is used to separate different statements. If you will use “;” between arguments, then “;;” is used to separate statements. It has to do with local settings.
  • As simple as, You can use the ‘;;’ character pair to separate multiple statements, something along the lines of the expression below:
If(
    TextInput1.Text = "";
    Set(isEmpty, true);; Set(isError, true);; Set(another: 123);
    Set(isEmpty, false);; SubmitForm(EditForm1))

Powerapps if statement contains text

Here we will discuss how to work with Powerapps if statement that contains text.

In this scenario, I want to make some text like (PowerApps) within a label that should appear with the green color (Highlighted). For this, We need to do these below things:

HtmlText = Substitute(
    "Show the PowerApps or Power BI value",
    "PowerApps",
    "<b style='color:Green;'>PowerApps</b>"
)
  • Once you apply the formula, you can see the PowerApps has been highlighted as green color like the below screenshot.
Powerapps if statement contains text
Powerapps if statement contains text
  • Suppose you want to concatenate the function, then you should set the HtmlText property of the Html Text control to the following:
Substitute(
           Concatenate(...),       // Type your Concatenate(...) formula here
           "PowerApps", 
           "<b style='color:Green;'>PowerApps</b>"
)

Powerapps if statement dropdown value

In this scenario, We will discuss how to use Powerapps If statement dropdown value.

  • On the Powerapps screen, there is a Dropdown box control and a Button input control. I want to make the button visible if any one of several dropdown values is selected else invisible.
  • In the below screenshot, you can see a Dropdown control is having items like [“PowerApps”, “Power BI”, “Power Automate”, “SharePoint Online”] (On it’s Items property)
Powerapps if statement dropdown value
Powerapps if statement dropdown values
  • Also, there is a Button control that will act depending upon the Dropdown control. Select the Button control and apply this below formula on its Visible property as:
Visible = If(
    Dropdown3.Selected.Value = "PowerApps" || Dropdown3.Selected.Value = "Power Automate",
    true,
    false
)

Where,

Dropdown3.Selected.Value = Dropdown control name

Powerapps if statement dropdown values
if statement dropdown value in Powerapps
  • The above formula specifies, When you will select the Dropdown value as “PowerApps” and “Power Automate“, then the Button will visible otherwise it will invisible as shown in the below screenshot.
if statement dropdown value in Powerapps
if statement dropdown value in Powerapps

Powerapps visible if statement

In this example, We will see how to work with Powerapps visible if statement.

  • I have a Powerapps Edit form where the fields are retrieved from a SharePoint list.
  • There is one Date Picker field and another a Check box control. As per my requirement, I want to make the Date received field visible if the checkbox control is checked. When the checkbox control is not checked, then the Date field will not visible.
  • To do this, follow these below steps:
  1. First of all, In the OnVisible property of your screen, create a Context Variable and set it’s value to false.
OnVisible = UpdateContext({cVisible: false})

Where,

cVisible = Context variable name and that value has set to false.

Powerapps visible if statement
Powerapps visible if statement

2. set the Date picker controls Visible property to the context variable, in this example that would be cVisible.

Visible = cVisible
Power apps visible if statement
Powerapps visible if statement

3. On the check box control, Set the OnCheck property to update the Context variable as:

OnCheck = UpdateContext({cVisible: true})
Powerapps visible in if statement
Powerapps visible in if statement

4. You can reset the context variable in the checkbox OnUnCheck property to reset as well to get a toggle effect.

OnUncheck = UpdateContext({cVisible: false})
Powerapps visible in if statements
Powerapps visible in if statements example

5. Now Save and Preview (F5) the app. Select the Check box control to Yes, then you can see the date field has been visible. Similarly, When you will select the check box control to No, then you can not see the date picker control.

visible if statement in Powerapps
PowerApps visible in if statements example

Powerapps nested if

Let us now discuss on PowerApps nested if.

  • Suppose there is a Slider input control in the Powerapps screen. Here my requirement is, I want to set below two conditions as:
    • If the slider value is more than 50, then I need to set the visible property to true.
    • If the slider value is less than 35, then I need to set the visible property to true.
    • In every other case, Visible should be false.
  • I have a Powerapps icon (Save). I set its Visible property as:
Visible = If(SliderWeight.Value > 50, true, If(SliderWeight.Value < 35, true, false))
  • But the formula does not work for me as I have used the nested if statement.
  • As I googled, found a solution to this requirement. Instead of Powerapps nested if statement, We can use the OR operator. Follow these below things:
  • The below screenshot represents the Powerapps Slider control that has a default value of 50.
Powerapps nested if
Powerapps nested if
  • There is a Save icon that will visible depending upon the slider value condition. Select the Save icon and apply this below formula on its Visible property as:
Visible = Slider1.Value > 50 || Slider1.Value < 35

Where,

Slider1 = Slider input control

Powerapps nested if statement
Powerapps nested if example
  • Now Save and Preview (F5) the app. Make the slider value 65, then you can see the save icon will visible to you. Similarly, make the slider value 40, then the save icon will not visible to you as shown below.
nested if statement in Powerapps
nested if statement in Powerapps

Powerapps OnSelect if statement

Here we will discuss about Powerapps Onselect if statement.

  • On the Powerapps form, there is a Yes/No field (toggle control) that is retrieved from a SharePoint list. Here what I want to do is, If the toggle control value is Yes, then it will navigate to the welcome screen, otherwise it will navigate to a warning screen. Both the condition should apply to the Powerapps Button control.
  • Select the Button input (Submit) and apply this below formula on its OnSelect property as:
OnSelect = If(
    DataCardValue18.Value = true,
    Navigate(
        Screen3,
        ScreenTransition.Fade
    ),
    Navigate(
        Screen4,
        ScreenTransition.Fade
    )
)

Where,

  1. DataCardValue18 = Yes/No toggle control that is set to true
  2. Screen3 = This is another screen (Welcome screen)
  3. Screen4 = This is the warning screen that will appear in the false case.
Powerapps OnSelect if statement
Powerapps OnSelect if statement
  • Now Save and Preview (F5) the app. Enter the fields and make the toggle value (Received) to Yes and click on the Submit button.
  • Once you click on the button, at the same time it will navigate to the welcome screen as shown in the below screenshot.
Powerapps OnSelect if statements
Powerapps OnSelect if statements
  • Similarly, Make the toggle value (Received) to No and then click on the Submit button. At the same time, you will see a warning screen as shown below.
OnSelect if statements in Powerapps
OnSelect if statements in Powerapps

Powerapps conditional formatting

Before doing anything, you should know what is the meaning of Powerapps Conditional formatting. Conditional formatting means it will change the look of specific rows or columns (in a Powerapps Gallery) depending upon the logic that you specify. Let’s have a look at the below scenario.

  • Below represents the SharePoint list (Products) that has a few text columns, Number columns, Choice column, Date column, etc.
Powerapps conditional formatting
Powerapps conditional formatting
  • Here what I want to do is, If any of the products is received as Yes, then that specific item should be green color otherwise the item should be red color.
  • On the Powerapps screen, Insert a Vertical Gallery control and make its Layout as “Title, subtitle, and body“.
  • Select the Gallery control and apply this below formula on its TemplateFill property as:
TemplateFill = If(
    ThisItem.Received = true,
    Green,
    Red
)

Where,

Received = SharePoint choice column

  • The above code specifies if the received value is Yes, then that particular item will be green color and if No, then that will be the red color as shown in the below screenshot.
Power apps conditional formatting
Power apps conditional formatting

Powerapps if statement with or

“Powerapps if statement with or” represents under the Powerapps Boolean logic functions like (And, Or, and Not functions). These functions are mostly used for the comparisons and tests.

  • Powerapps And function returns true if all arguments are true.
  • Powerapps Or function returns true if all arguments are true.
  • Powerapps Not function returns false if its argument is true and it returns true if its argument is false.

You can use different types of operators to perform these same operations using either Visual Basic or JavaScript syntax. Follow this below table:

Function notation Visual Basic operator notation JavaScript operator notation
And( A, B ) A And B A && B
Or( A, B ) A Or B A || B
Not( A ) Not A ! A

Lets take an example. Suppose there is a formula like A > 100 evaluates to the Boolean value true if A is greater than 100. If A is less than 100, then the formula evaluates to false. All these Powerapps functions work with logical values. You can’t pass them a number or a string directly.

Syntax:

  1. And:
And( LogicalFormula1, LogicalFormula2 [, LogicalFormula3, ... ] )

2. Or:

Or( LogicalFormula1, LogicalFormula2 [, LogicalFormula3, ... ] )

3. Not:

Not( LogicalFormula )

Where,

  • LogicalFormula(s) = This is Required where the Logical formulas to evaluate and operate on.

To learn more about the Powerapps functions, you can follow this below article:

And, Or, and Not functions in Power Apps

Powerapps if statement in patch

  • When you will work with the PowerApps Patch function, you may think that whether is it possible to use an If statement within a patch function.
  • To answer this question is, Yes you can use the PowerApps if statement in the Powerapps Patch function.
  • Below represents a simple Patch function formula (with If statement) that you can refer to as:
Patch(
  'SPO-List-Name',
  Defaults('SPO-List-Name'),
  {
      'Location': txtLocation.Text,
      'City': txtCity.Text,
      'Country': txtCountry.Text,
      'Field': If(dropdownA.SelectedText.Value = "One", txtOne.Text, txtTwo.Text)
  }
)

Where,

  1. SPO-List-Name = SharePoint list name where you want to create the new item
  2. ‘Location’, ‘City’, ‘Country’, ‘Field’ = SharePoint columns
  3. txtLocation, txtCity, txtCountry, txtOne, txtTwo = These are the Powerapps text input controls

Powerapps if statement with toggle

Here we will see how a Toggle value returns in if statement. Lets take a simple example.

Example:

  • In the Powerapps screen, Insert a Toggle control and a Label control. Apply this below formula on the Text property of Label control.
Text = If(Toggle1.TrueText="On", Text(Toggle1.Value), "")

or

Text = If(Toggle1.TrueText="On",Toggle1.Value,"")

Where,

  1. Toggle1 = Toggle control
  2. TrueText = This is the property of the toggle control
Powerapps if statement with toggle
Power apps if statement with toggle
  • Save and Preview the app. Make the toggle control value to On, then you can see the Label value will be true. Similarly, make the toggle control value to Off, then the label control value will be false as shown below.
Powerapps if statement with toggle
Powerapps if statement with toggle
  • Based on the If() construct, as you know the If statement syntax: If(logical test, true_value, else_value)
  • Similarly, there are some logical checks in the If statement that I want to share with you. Check these below statements:
1. If(true, true, false)

This above statement represents, if the logical check is true, then the result is a true_value which is true otherwise false.

2. If(false, true, false)

This above statement represents, if the logial check is false, then the result is a else_value which is false.

3. If(true, true, "sometext")

The above statement represents, if the logical check is true, then the result is the true_value which is true otherwise it will display the string value (“sometext”) that you have given.

4. If(false, true, "sometext")

The above statement represents, if the logical check is false, then the result is the else_value which should be “sometext” but comes back as false.

  • Another most important thing you should know i.e.,

When the true_value is a boolean type, PowerApps for some reason is converting the else_value to a boolean type as well and returning the result. If the result is not explicitly boolean true, it’s false. In the above, “sometext” is not equal to true, therefore the result is false.

If(false, true, 0) 		result: false
If(false, true, 1) 		result: true
If(false, true, "true") 	result: true
If(false, true, "True") 	result: false

0 can be logically auto-converted to boolean as false – anything greater than 0 is true.
“true” can be auto-converted to boolean as true – anything else is false.

Powerapps if statement do nothing

“Powerapps if statement do nothing”, At first, when you will read this sentence, you may get confuse on that what exactly it is. Lets take a simple scenario.

  • I have a PowerApps Blank screen. On that screen, I have a text input control i.e. TextInput1. Here what I would like to do is, if the text input control is blank, then do nothing otherwise it will go to an alert screen.
  • All these functions should perform on the Powerapps Button control.
  • Select the Powerapps Button input and apply this below formula on its OnSelect property as:
OnSelect = If(
    !IsBlank(TextInput1),
    Navigate(
        Screen4,
        ScreenTransition.Cover
    )
)

Where,

  1. TextInput1 = Text input control name (Name)
  2. Screen4 = When the text input field will have some text, it will navigate to the alert screen
Powerapps if statement do nothing
Powerapps if statement do nothing
  • Save and Preview the app. Enter some text to the input field and press the button, then you can see an alert screen will appear as shown below. Similarly, if there is no text inside the input field, then nothing will happen once you will click on the button control.
Power apps if statement do nothing
Power apps if statement do nothing

Also, you may like these below Powerapps tutorials:

In this PowerApps Tutorial, We will discuss what is Powerapps If and Switch function and it’s all syntaxes. Also by taking some simple scenarios, We discussed these below topics as:

  • Powerapps if statement examples
  • Powerapps if statement multiple conditions
  • Powerapps if statement multiple actions
  • Powerapps if statement contains text
  • Powerapps if statement dropdown value
  • Powerapps visible if statement
  • Powerapps nested if
  • Powerapps OnSelect if statement
  • Powerapps conditional formatting
  • Powerapps if statement with or
  • Powerapps if statement in patch
  • Powerapps if statement with toggle
  • Powerapps if statement do nothing
  • Hello,

    Is it possible to have more than 3 if statements?
    Example:
    If(CONDITION A, RESULT A,
    CONDITION B, RESULT B,
    CONDITION C, RESULT C,
    CONDITION D, RESULT D,
    DEFAULT RESULT)

  • >