cancel
Showing results for
Did you mean:
Highlighted
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

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

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

Announcements

Check it out!

#### Power Apps Community User Group Member Badge

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

#### Power Platform World Tour

Find out where you can attend!

#### Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

#### Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,338)