### Performing Calculations and Entering Data with the IF Function

### How the IF Function Works

The IF function adds decision making to Excel spreadsheets by testing a specified condition to see if it is true or false.

If the condition is true, the function will carry out one action. If the condition is false, it will carry out a different action.

### The IF Function Syntax and Arguments

A function's syntax refers to the layout of the function and includes the function's name, brackets, and arguments.

The syntax of the function is:

=IF(logic test, value if true, value if false)

The logic test is always a comparison between two values. Comparison operators are used, for example, to see if the first value is greater than or less than the second, or equal to it.

For example, in the image above the *logic test* compares an employee's earnings located in column B to see if they are greater than $30,000.00.

=IF(B2 > 30000, B2 * 1%, 300)

Once the function determines if the logic test is true or false, it carries out one of the two actions specified by the *value if true* and *value if false* arguments.

The types of actions that the function can carry out include:

- performing calculations using a formula or entering number data
- displaying text statements in designated worksheet cells,
- leaving the target cell blank.

### Performing Calculations with the IF Function

The IF function can perform different calculations depending on whether the function returns a true value or not.

In the image above, a formula is used to calculate a deduction amount based on employee earnings.

=IF(B2 > 30000, B2 * 1%, 300)

The deduction rate is calculated using a formula entered as the *value if true *argument. The formula multiplies the earnings located in column B by 1% if the employee's earnings are greater than $30,000.00.

### Entering Data with the IF Function

The IF function can also be set up to enter number data into a target cell. This data could then be used in other calculations.

In the example above, if an employee's earnings are less than $30,000.00, the *value if false* argument has been set to insert a flat rate of $300.00 for the deduction rather than using a calculation.

**Note:** Neither the dollar sign nor comma separator is entered with the numbers 30000 or 300 in the function. Entering either one or both creates errors in the formula.

- Excel functions use the comma as a separator between arguments, so entering commas with numbers leads Excel into believing that more than three arguments have been entered for the IF function.
- Since dollar signs are text characters, entering them with numbers leads Excel into believing that a typing error has been committed and it offers to correct it.

### Displaying Text Statements or Leaving Cells Blank with the Excel IF Function

### Displaying Words or Text Statements with the IF Function

Having text displayed by an IF function rather than a number can make it easier to find and read specific results in the worksheet.

In the above example, the IF function is setup to test whether students taking a geography quiz correctly identify the capital cities for a number of locations in the South Pacific.

The logic test of the IF function compares the students' answers in column B with the correct answer entered into the argument itself.

If the student's answer matches the name entered into the logic text argument, the word Correct is displayed in column C. If the name does not match, the cell is left blank.

=IF(B2 = “Wellington”,"Correct"," ")

To use single words or text statements in an IF function each entry must be enclosed in quotes, such as:

- the
*logic test*argument:*B2 = "Wellington"* - the
*value if true*argument*"Correct"*

### Leaving Cells Blank

As shown for the*value if false*argument in the example above, cells are left blank by entering a pair of empty quotation marks (

**" "**).