25 Power Apps IF Function Examples

25 Power Apps IF Function Examples

The Power Apps IF Function performs a logical comparison to see if the result is true. Then it conditionally executes the next lines of code based on whether the result was true or false. The examples on this page show how the Power Apps IF Function works for every data type.

Important note: for most examples the IF Function the 2nd argument is true and the 3rd argument is false. These true and false values are only placeholders. They should be replaced with your own code in the real-world.

Matthew Devaney

Subscribe
Notify of
guest

25 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Alexsolex
Alexsolex
2 years ago

I try to explain to all new powerapps developers or citizens that writing “if(my condition,true,false)” is useless and make the readability of code worse.
Can you tell us if there is a real need of this syntax when writing just “myCondition” in a Boolean field is enough ?

Andrea
Andrea
2 years ago

Hi Matthew. Really handy list, thank you.

I’m not sure if you also do this, but when I have a conditional with OR like this:

If(varInventoryItem=”Samsung” Or varInventoryItem=”LG” , true, false)

I prefer to write it as:

If(varInventoryItem in [“Samsung” , “LG”] , true, false)

as it makes it easier to read and to add more items to the list (in this case, of Manufacturers).

What do you think?

Cheers,
Andrea

Jérôme Rancourt
Jérôme Rancourt
2 years ago

Hi Matthew, I tried to modify nested if in power automate following what is explained on this article and could not save the compose action….

First, i created Initialize variable action of string type ‘varTransport’ and the value is based on a Msforms Input

Then a compose action : if(“Train” in variables(‘varTransport’),true,”Autobus” in variables(‘varTransport’),true,”Location automobile” in variables(‘varTransport’),true,false)

Am I missing something ?
Thanks,

Heidi
Heidi
2 years ago

I wish this article had of existed when I started my PowerApps journey 2 years ago. It would have saved me many tears. Especially the logical operators section. Will be sharing this with the up and comers I am mentoring.

Drew Thompson
2 years ago

Hi Matthew:

Thanks for this – did not realize that there was a switch style statement as you showed in Check multiple conditions!

cheers

Pete Filicetti
Pete Filicetti
2 years ago

Matthew,
I’m a huge fan of your work. Thanks for everything you do.

In reading the article, I had a question:

Code:
Check if the Buyer column of varInventoryItem has a user name equal to “Sarah Green”

If(varInventoryItem = Buyer.’Display Name’, true, false)

Wouldn’t it be as follows?:
If(varInventoryItem.Buyer.’Display Name’ = “Sarah Green”, true, false)

Best,
Pete

LDK
LDK
2 years ago

Check if the OrderStatus of varInventoryItem equals “Ordered”

If(varInventoryItem.OrderStatus.Value, true, false)

should this code like below

If(varInventoryItem.OrderStatus.Value = "Ordered", true, false)

thank you for your great posting

Fernando Hunth
Fernando Hunth
2 years ago

I think this Output is not ok:

If(!varOnSale, true, false)

Oscar
Oscar
2 years ago

I tried this syntax but did not get the desired result. I ended up using a switch.
Also, it works if I treat it with nested If statements. Has something changed since you wrote this?
If(
varTitle = “Dishwasher”,
“Dishwasher was found!”,
varTitle = “Kitchen Sink”,
“Kitchen Sink was found!”,
varTitle = “Refrigerator”
“Refrigerator was found!”,
“No matches found”
)

Lütfi
2 years ago

Hi @Matthew,

Sorry for late reply, correct me if I am wrong but this code that you on example shouldn’t return false?

Regards

If(
    varInventoryItem.Manufacturer="Samsung"
    And varInventoryItem.OnSale,
    true,
    false
)
Sindiswa
Sindiswa
2 years ago

If(
  IsBlank(DataCardValue35.SelectedItems),Set(varTask,true),
  IsBlank(DataCardValue1.SelectedItems),Set(varApplicationArea,true),
  IsBlank(DataCardValue36.SelectedItems),Set(varTimein,true),
  IsBlank(DataCardValue40.SelectedItems),Set(varTimeout,true), 
  TimeValue( DataCardValue36.Selected.Value)>=TimeValue(DataCardValue40.Selected.Value), Set(varLabel11, true),Set(varLabel11, false) Or

IsBlank(DataCardValue8.SelectedItems),Set(varTask,true),
  IsBlank(DataCardValue2.SelectedItems),Set(varApplicationArea,true),
  IsBlank(DataCardValue4.SelectedItems),Set(varTimein,true),
  IsBlank(DataCardValue5.SelectedItems),Set(varTimeout,true), 
  TimeValue( DataCardValue4.Selected.Value)>=TimeValue(DataCardValue5.Selected.Value), Set(varLabel11, true),Set(varLabel11, false),

  IsBlank(DataCardValue10.SelectedItems),Set(varTask,true),
  IsBlank(DataCardValue3.SelectedItems),Set(varApplicationArea,true),
  IsBlank(DataCardValue14.SelectedItems),Set(varTimein,true),
  IsBlank(DataCardValue15.SelectedItems),Set(varTimeout,true), 
  TimeValue( DataCardValue14.Selected.Value)>=TimeValue(DataCardValue15.Selected.Value), Set(varLabel11, true),Set(varLabel11, false),
  
  IsBlank(DataCardValue7.SelectedItems),Set(varTask,true),
  IsBlank(DataCardValue17.SelectedItems),Set(varApplicationArea,true),
  IsBlank(DataCardValue29.SelectedItems),Set(varTimein,true),
  IsBlank(DataCardValue24.SelectedItems),Set(varTimeout,true), 
  TimeValue( DataCardValue29.Selected.Value)>=TimeValue(DataCardValue24.Selected.Value), Set(varLabel11, true),Set(varLabel11, false),
  

This is my if statement but its not working says can’t evaluate formula. I have 4 forms and in each I want to validate if the forms aint blank and that time in and time out can’t be the same. Please help

Lindsay
Lindsay
1 year ago

Hey! I think I’ve searched the entire internet and I can’t find anything with the past 2 years about making a data card in Power Apps conditionally required based on a response from another data card. The code that I can find is older than 2021 and does not work. Do you know what I would put in the ‘Required’ field of a datacard I want to make required based on a response from a previous datacard?

Polina Bond
Polina Bond
1 year ago

Hello Matthew, thank you for your wonderful post.
I was wondering if you might have a solution for setting up a column in model-driven apps in power apps using formula as data type. I’ve tried various formulas I found posted and shared across the internet, but unfortunately, I didn’t find anything that would work. I am trying to text column Owner with the lookup data type against defined values (the user names). However, it doesn’t seem to work in a simple Excel manner, aka If(Owner=”Bob Marley”,”750000″,”0″) – see screenshot attached. Using calculated data type setup for the column doesn’t work as Owner field could only have if statement of “contains data” or “doesn’t contain data” – see screenshot 2.

I would really appreciate any advise, thank you in advance.

Screenshot 2024-04-10 at 11.31.51.png
Rudi Olivier
1 year ago

Hi there.
Thanks for the nice info love your stuff.
I have an IF scenario.
I have many SharePoint lists that I want to display in PowerApps based on n condition.
If the previous answer is “Option1” then SP List A must display but if “Option2” is selected SP List B must display. and so on and so on.
I get as far as [If(PlantDataCard.Selected.Value = “Salads and Pickles”,
DisplayList(‘[OT] Devices – Bethlehem – Salads and Pickles’),
false)} but it is not happy with the “DisplayList” section.

Alan
Alan
3 months ago

I believe your example in the “IF Condition Using Multiple Logical Operators” section will result in an error. You are missing an open parentheses.