cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
JonasH
Level: Powered On

If in If

Hey,

Is there an opportunity to have an if statement in and if staement?

I mean something like

if(condition)
{
     if(condition)
     {
          statement
     }
     elseif
     {
          statement
     }
     else
}
else
statement

or do I have to use if(condition, statement, condition2, statement2, condition3, statement3)?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: If in If

@JonasH 

Yes, you can use nested if statements in PowerApps.  Here's an example.  Assume "x" is the name of a Number type variable.

 

If(
    x > 10,
    If(
        x <= 15,
        "Number is between 10 and 15
        x <= 20,
        "Number is between 16 and 20,
        "Number is greater than 20
    ),
    "Number is less than 10"
)

 

However, in many cases flattening the IF statement will make your code more readable.  In my opinion, the code below is easier to understand.

 

If(
    And(x > 10,x <=15),"Number is between 10 and 15
    And(x > 15,x <=20),"Number is between 16 and 20,
    x > 20,"Number is greater than 20,
    "Number is less than 10"
)

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

View solution in original post

3 REPLIES 3
Super User
Super User

Re: If in If

@JonasH 

Yes, you can use nested if statements in PowerApps.  Here's an example.  Assume "x" is the name of a Number type variable.

 

If(
    x > 10,
    If(
        x <= 15,
        "Number is between 10 and 15
        x <= 20,
        "Number is between 16 and 20,
        "Number is greater than 20
    ),
    "Number is less than 10"
)

 

However, in many cases flattening the IF statement will make your code more readable.  In my opinion, the code below is easier to understand.

 

If(
    And(x > 10,x <=15),"Number is between 10 and 15
    And(x > 15,x <=20),"Number is between 16 and 20,
    x > 20,"Number is greater than 20,
    "Number is less than 10"
)

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

View solution in original post

Dual Super User
Dual Super User

Re: If in If

You can definately nest If() functions, but I'm not sure that's really what you want.  You would do it like this

If(condition,If(condition2,true,false),if(condition3),true, false))

In this example Condition2 is only tested if condition is true and Condition3 is only tested if Condition is false.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
MrNappa
Level: Powered On

Re: If in If

Yes you can (see posts above).

 

I just want to note that depending on the situation you can also use 'Switch':

Switch( TextInput1.Text,
  "foo", Notify( "foo!" );
  "bar", Notify( "bar!" );
  Notify( "probably baz..." );
);

Just keep in mind that the switch condition is only evaluated once and you can not use 'formula matching'.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (3,883)