Although SUM is the most frequently used function in Excel, the very useful IF function should also be in your Excel bag of workbook tricks. Basically, the IF function tests whether a condition is true or false and then performs an action such as a calculation or data entry. How often are you sorting or filtering data to manually locate Excel entries that might require additional data entry or auditing? The IF function can automatically evaluate your data based on the condition or conditions that you create.
The cell or entry that is evaluated may be a formula, value, or text; the displayed result may also be a formula, value, or text answer. For example, if an amount is more than 5% over the budgeted amount, then you might display “OVER”, otherwise show “OK.”
First, let’s look at the structure (syntax) of the IF function. As with other Excel functions, we start with =(equals) and then the function name followed by an open parentheses, such as =IF( . The logic and structure of an IF function is:
=IF(what you are testing/evaluating, what to do if true, what to do if false)
For instance, what if we want to calculate an analysis where, if the total is greater than or equal to $1000, then a $100 bonus is entered into the formula cell; otherwise, no bonus is given.
The formula would look like: =IF(B2>=1000, 100, 0) where B2 is the value being evaluated. As with other formulas, the results will update if values are changed. And, as with other formulas, this calculation can be copied down or across to calculate additional values.
The results of the IF function can also be a text entry that you may want to filter for checking data, such as =IF(B14=E14, “OK”, “AUDIT NEEDED”).
In this sample function, if the two cell values are the same, the result is “OK”, otherwise the answer is “AUDIT NEEDED”. Notice that text entries are surrounded by quotes (to create a character string) with the formula commas outside the quotes. Note that it doesn’t matter if you add spaces after each comma.
Not every evaluation has only one condition limited to two different actions. Sometimes, you may have 3 or more possibilities, for instance, different calculations based on ranges or levels of values. This calls for nested/multiple IF functions. You can also nest other functions within an IF function as needed to create your logical condition. For instance, an IF function might apply a condition to the results of a SUM or AVERAGE function.
For example, the following IF function works with these options:
The formula would look like:
NOTE: When nesting with any worksheet function, the equals sign is only required with the initial function statement, i.e. the 2nd IF in our nested formula does not need an equals sign. You can use up to 64 levels of nesting in a formula but that’s a lot of nesting!
Ready for some more function fun? The IF function can be combined with AND, OR, NOT functions to create more detailed evaluations that apply multiple conditions where all expressions are true (AND), only one expression needs to be true (OR), or the opposite (NOT) is true.
Looking at the breakout of Excel functions is an easy way to learn how to create your own especially with nested functions. This next example, shown below, is designed to test:
Discover more Excel shortcuts, tips and tricks here.
By Dawn Bjork, MCT, The Software Pro®
Microsoft Certified Trainer, Technology Speaker, Software Consultant