If

if(boolean; expressionA; expressionB)

If boolean is true, evaluate expressionA, otherwise evaluate expressionB.

Data Types: number, table
Alternative Names/Symbols:

Examples:

  • if(A > 0; 100/A; 0) : returns 100 divided by A if A is greater than 0 (true) or 0 if it is equal to or less than 0 (false)

Additional Information:
If statements are used for conditional situations. If statements can be used by themselves or nested, meaning a second if statement is used within a first (the example below uses a nested if statement). In this example, a profit sharing formula has three levels:
- If net income is less than or equal to $1 million, there is no profit sharing.
- If net income is greater than $1 million but less than or equal to $5 million, profit sharing is 2% of monthly pay.
- If net income is greater than $5 million, profit sharing is 4% of monthly pay.

With a monthly base of $3000, what is the profit sharing amount if the company's net income is $700,000, $2 million and $10 million?

The equation for calculating this profit sharing formula is:

NetPay = BasePay + if(NetIncome <= 1000000; 0;
if(NetIncome > 1000000 && NetIncome <= 5000000; BasePay * .02; BasePay * .04))

where
- NetPay is the final, monthly net pay including base pay and profit sharing. BasePay is the monthly base pay.
- NetIncome is the net income earned by the company.

The format for if statements is if(conditional true; do this; otherwise do this). To break down the equation:

  • The first if statement says if net income is less than or equal to (<=) 1,000,000, add 0 otherwise do the second if statement.
  • The second if statement says if net income is greater than (>) 1,000,000 and (&&) net income is less than or equal to (<=) $5,000,000, then add in 2% of the base pay. If it doesn't meet this condition, than net income must be larger since we took care of all other conditions. Add in 4% of base pay instead.
  • Note that nested if statements read from left to right. If the first criteria is true, the solver will not continue to the false statement. Because of that, the formula could be written as: NetPay = BasePay + if(NetIncome <= 1000000; 0; if(NetIncome <= 5000000; BasePay * .02; BasePay * .04)) leaving out "NetIncome > 1000000 &&" in the second, nested if statement.