An if statement checks it meets a condition and performs an action accordingly. If it doesn't meet the condition, it performs a different action.
You can use an if statement to return specific values based on the condition.
A typical if statement uses the following format:
Condition ? Instruction 1 : Instruction 2
The expression is therefore saying:
If the condition is true THEN apply instruction 1, ELSE apply instruction 2.
When constructing the if statement, you must always include at least one condition, an instruction 1 and an instruction 2.
You can specify more than one condition with different results within one expression. This is a nested if statement.
Nested if statements use the following format:
Condition 1 ? Instruction 1 : Condition 2 ? Instruction 2 : Instruction 3
where:
The expression is therefore saying:
If condition 1 is true THEN apply instruction 1, ELSE if condition 2 is true THEN apply instruction 2, ELSE apply instruction 3.
When constructing a nested if statement, you must end the statement with an else instruction to cover when it doesn't meet the specified conditions.
Here's is an example using the Sales Ledger Analysis Type field:
SALES_LEDGER.ANALSYSIS1 LIKE "NORTH" ? "Michael" : SALES_LEDGER.ANALSYSIS1 LIKE "SOUTH" ? "Sharon" : "Not Assigned"
The above statement will return "Michael" for all items in the search using "North" as the sales analysis type. "Sharon" for any using "South", and "Not Assigned" for any that aren't "North" or "South".
Using if statements provide far more flexibility than conditional formatting.
If you're looking to format your expression, for example make the colour red when it meets a condition, you need to use conditional formatting.
![]()
Keep your employees smiling
You can offer your people more with Sage Employee Benefits, which makes it easy to provide health and wellbeing benefits, and a range of discounts on shopping, holidays, and family activities.
