cancel
Showing results for
Did you mean:
Highlighted Helper II

## 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
Highlighted Super User

## Re: If in If

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."

3 REPLIES 3
Highlighted Super User

## Re: If in If

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."

Highlighted Dual Super User II

## 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 you like my response, please give it a Thumbs Up.
Highlighted ## 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'.

Announcements Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment. #### August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge! #### Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.   