How to use the if() expression in Power Automate
Use if(test, valueIfTrue, valueIfFalse) to return one of two values inside a single expression. It replaces a Condition action when you only need to choose a value, such as a status label or a default.
What is the syntax of the if() expression?
The function takes three parts: a test that returns true or false, the value to return when the test is true, and the value to return when it is false. Example: if(equals(variables('amount'), 0), 'Free', 'Paid').
Add it in a Compose action, in a dynamic content field (open the Expression tab) or in a Set variable action. The result is the value of the branch that matches. The test must produce a true or false value. A plain text value such as 'yes' is not a valid test.
How do you write the test?
Use a comparison function inside the first part. equals() checks for the same value. greater() and less() compare numbers and dates. empty() checks for a blank value.
Microsoft does not say whether equals() ignores case, so lower both sides to be safe. To ignore case, wrap both sides in toLower(), as in equals(toLower(triggerOutputs()?['body/Status/Value']), 'approved'). See change text case for the details.
How do you test more than one thing?
Join the tests with and() or or(). and() is true only when every test is true. or() is true when at least one test is true. not() reverses a result.
Example: if(and(greater(variables('total'), 1000), equals(variables('region'), 'West')), 'Manager', 'Auto'). The result is 'Manager' only when both tests pass. For prefix checks inside a test, see startsWith and endsWith.
How do you return a default value when a field is empty?
Test with empty(): if(empty(triggerOutputs()?['body/Notes']), 'No notes', triggerOutputs()?['body/Notes']). The flow returns the fallback text when the column is blank.
A blank column can arrive as null. Use the safe-access form ?['body/Notes'] so the flow does not fail on a missing property. If a Condition action reads an empty field wrongly, see condition field empty.
Can you nest one if() inside another?
Yes. Put a second if() in the false part: if(equals(x, 'A'), 'Low', if(equals(x, 'B'), 'Medium', 'High')). The flow checks the first test, then the second.
Nesting becomes hard to read after two levels. For three or more fixed outcomes, a Switch action is clearer and easier to change later.
When should you use a Condition action instead?
Use if() when you only choose a value. Use a Condition action when each branch runs different actions, such as sending an email in one branch and updating a list in the other.
An expression keeps the flow short and shows in the run history as one step. A Condition shows both branches on the canvas, which helps a second person read the flow.
FAQ
Does if() work in a SharePoint column formula?
No. Power Automate if() and the SharePoint calculated column IF() use different rules. The SharePoint version uses uppercase IF and different functions.
Can if() return a number or an object?
Yes. Each branch can be text, a number, a true or false value, an array or an object. Keep both branches the same type so later steps do not fail.
Why does my if() return the false value every time?
Check the test. A text compare can fail on a case difference or on extra spaces. Wrap the value in toLower() and trim() first.
Sources
- Reference guide to workflow expression functions in Azure Logic Apps and Power Automate
- Use expressions in conditions in Power Automate