You are on page 1of 38

EXCEL BASIC FORMULAS AND FUNCTIONS

Table of Contents
Excel Functions and Formulas .................................................................................... 1 Formula Basics ........................................................................................................... 1 Viewing formulas ..................................................................................................... 2 Entering formulas .................................................................................................... 3 Range names .......................................................................................................... 3 Editing formulas ....................................................................................................... 5 Copying formulas..................................................................................................... 5 Relative, absolute and mixed references in formulas .............................................. 8 Converting formulas to values ............................................................................... 10 Using formulas in conditional formatting................................................................ 11 Function Basics ......................................................................................................... 12 What is a function? ................................................................................................ 12 Categories of functions .......................................................................................... 13 Entering functions .................................................................................................. 13 Nested functions ................................................................................................. 16 Editing functions .................................................................................................... 16 Working with Functions ............................................................................................. 17 Common Math and Statistical functions ................................................................ 17 The SUM function .............................................................................................. 17 The AVERAGE, MAX and MIN functions .......................................................... 19 The COUNT functions .................................................................................... 20 Averaging non-zero values ................................................................................ 21 Using SUM to calculate a running total .............................................................. 21 The SUMIF function ........................................................................................... 21 The RAND and INT functions ............................................................................ 22 The MOD and ROW functions ........................................................................... 22 3-Dimensional formulas ......................................................................................... 23 Financial functions ................................................................................................. 25 The PMT function .............................................................................................. 26 The other PMT-related functions ....................................................................... 27 Data tables ......................................................................................................... 27 Goal Seek .......................................................................................................... 28 Date/Time functions............................................................................................... 29 Date/time stamps and the NOW and TODAY functions .................................... 30 Date calculations and functions ......................................................................... 31 Using AutoFill with dates ................................................................................... 32 Time calculations and functions ......................................................................... 32 Text functions ........................................................................................................ 33 Logical functions ....................................................................................................... 34 Using the IF function to make decisions ............................................................ 34 Nested IF functions ............................................................................................ 35

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page ii

Excel Functions and Formulas


Excel is the ideal application for organizing and analyzing data. But its real power is in its ability to perform calculations on the data. You tell Excel how to calculate the data in your worksheet by entering formulas. In this class, we will examine a number of different kinds of formulas, especially those that use Excels built-in functions. The pictures in this manual are taken from Microsoft Excel 2010. However, all the features we will discuss in this class are the same in the earlier versions of Excel, unless noted otherwise.

To demonstrate and practice the topics in this class, we will use several worksheets contained in the workbook Functions and Formulas.xls. The file is located in the STUDENT folder on the C: drive, as well as on the disk that accompanies this manual. Exercises are preceded by the symbol throughout the manual.

Formula Basics
First, lets review some basic information about formulas.
Start Excel and open the Functions and Formulas workbook. Select the Formula Basics worksheet to illustrate the following points.

A formula always starts with an equal sign (=), as in the formula in cell D4, =B4+C4. (You can also start a formula with +, - or @, the function symbol used in Lotus 1-2-3, but Excel will replace those symbols with =.)

The formula can include: Cell references, like B4 and C4 in the formula above. Range names, like the name Sales in =SUM(Sales) in B8. Functions, such as the SUM function in B8. Operators +, -, *, /, ^, & Constants, like the numbers 2 and 1.1 in the formula in B13.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 1

When a formula contains more than one type of operator, Excel calculates the formula based on its order of operations rules. The operators and their order of precedence are listed below. Expressions inside parentheses are calculated first Exponentiation (^) Multiplication (*) and division (/) Addition (+) and subtraction (-) Text concatenation (&) Logical comparisons (=, <, >, <=, >=, <>)

Any operators at the same precedence level are evaluated from left to right in the formula. For example, here is how Excel calculates the formula in B13: =(B4+B6)/2*1.1 B4 and B6 are added together, because the calculation is enclosed in parentheses. Then the result of the first calculation is divided by 2. Finally, the result is multiplied by 1.1.

If we had not included the parentheses in the formula, Excel would have first divided B6 by 2, multiplied the result by 1.1, and then added the result to B4, giving us an incorrect answer!

Viewing formulas
When a formula is entered into a cell, the cell contains the formula, but it displays the value of the calculation. The formula is displayed in the formula bar.

To see all the formulas in your worksheet, go to the Formula Ribbon, and select Show Formulas. This causes all of the formulas to be displayed in their cells. To turn off this option, go through the same procedure and click on the checkmark to remove it.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 2

There is a faster way to view all the formulas using a keyboard shortcut. Simply press CTRL+` (the accent or left quote character, on the same key as the ~ symbol) to turn on the display of all the formulas. Press the key combination a second time to return to the normal display.

Entering formulas
Formulas can be entered manually by typing the entire formula into the cell or the formula bar. Or you can use the point-and-click method to select the cell(s) to be used in the formula. Lets enter a formula to compute Januarys profit (total income minus expenses).
Select cell F4 and type =. Click on cell D4 to add it to the formula. Type (minus sign) and click on cell E4. Press Enter to enter the formula and display its value.

Range names
A name can be assigned to a cell or a range of cells, and then you can use that range name in your formulas throughout the workbook. In addition to making formulas more descriptive, range names also provide a very quick way to select the range of cells. There are several ways to create range names. The following procedure describes two methods. Using the Name Box: 1. Select the cell(s) to be named. 2. Click inside the Name Box (to the left of the formula bar). 3. Type the name. See the naming rules below. 4. Press Enter to assign the name to the range of cells. Using the Ribbon 1. Select the cell(s) to be named. 2. Select the Formula Tab 3. Click then Define Name Button

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 3

4. Type the name in the field at the top of the dialog box. 5. Click OK to assign the name. The rules for range names: The first character must be an alphabetic character or underscore (_). The remaining characters (up to a total of 255 characters) may be letters, numbers, underscores or periods. Spaces are not allowed. The name cannot resemble a cell reference, such as X257 or R12C10. Excel will treat such names as cell references. Names are not case-sensitive. However, we usually use uppercase for the first letter of words within the name to make it more readable.

After range names have been assigned, you can use a name in a formula in place of the cell references for the range. The easiest way to do this is by pressing the F3 (Paste Name) function key and selecting the name from the dialog box.

In the following exercise, we will create and use a range name in the formula that computes the tax on our profits.
Click in cell E11, which contains the tax rate. Click in the Name Box, type Tax_Rate and press Enter to assign the name.

Select cell G4 and type =F4*. Press the F3 key, select Tax_Rate in the Paste Name dialog box and click OK. Press Enter to complete the formula and display the tax for January. To see how range names can be used to quickly select a range, click the down arrow

next to the Name Box, and select Tax_Rate. Excel goes directly to the named range and makes cell E11 the active cell.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 4

Editing formulas
If you want to replace the contents of a cell, you simply select the cell and enter the new value. But sometimes you want to modify, or edit, just a part of the cell contents. You can edit the contents either in the cell or in the Formula Bar. There are three ways to get into Edit mode: Double-click on the cell. The blinking cursor appears somewhere within the formula. Select the cell and press the F2 key. The blinking cursor appears at the end of the formula. Or select the cell and click on the formula in the Formula Bar. The blinking cursor appears where you clicked. When Excel is in Edit mode, the word Edit appears at the left side of the Status Bar. To get out of Edit mode, press Esc to cancel any changes you made or Enter to accept the changes.
Try each of the three methods above on the formula in cell G4.

Copying formulas
A formula can be copied from one cell to another by using the Copy and Paste buttons or edit menu selections. To copy a formula into adjacent cells, you can also drag it using the fill handle, the small black box in the lower right corner of the selected cell(s). Excel will automatically adjust all relative cell references in the formula to point to the correct cells. (See the discussion of relative and absolute references below.)
Select cells F4:G4 and copy the formulas to F5:G6.

Click here and drag to here

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 5

The cell references in the Profit column are adjusted relative to the new location of

the formula. So when the formula in F4, =D4-E4, is copied to cell F5, it becomes =D5-E5.
In the Tax column, the part of the formula that points to the entry in the Profit column

is adjusted. But the Tax_Rate, which is an absolute reference is not changed. When the formula in G4, =F4*Tax_Rate, is copied to cell G5, it becomes =F5*Tax_Rate.

Occasionally you will need to copy a formula without changing the relative cell references. To do this, you must copy the formula as text. There are two simple ways to do this. If the destination cell is immediately below the formula to be copied, you can use the keyboard shortcut CTRL+ (the single quote next to the Enter key). This copies the contents of the cell above it without changing the cell references, and puts the cell in Enter mode, with the insertion point at the end of the formula.
The formula in B13 calculates a 10% increase over the January and March average.

Lets say that in B14 we need to perform a similar calculation with a 15% increase.
Select B14 and press CTRL+. The formula is copied from B13, with a blinking

cursor at the end. Type 5 and press Enter. The new formula calculates a 15% increase over the January and March average.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 6

The second method allows you to copy a formula to any cell without changing the relative references. It requires the following five steps: First select the cell that contains the formula. Then drag across the text in the formula bar to highlight the formula. (This puts the cell into Edit mode.) Click the Copy button to copy the formula to the Windows clipboard. Then press Enter or Esc to get out of Edit mode. (If you dont exit Edit mode, you will change the formula when you click on the destination cell!) Finally, select the destination cell and click the Paste button.

Lets say we need to calculate the same average in B15 that we have in B12. Click on cell B12 and select the text in the formula bar.

Click the Copy button. Press Enter to get out of Edit mode. Select cell B15 and click the Paste button. The formula is entered unchanged into

the new cell.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 7

Relative, absolute and mixed references in formulas


As we saw in the previous section, when a formula that contains relative cell references is copied to a new cell, Excel adjusts the references so the formula will perform the calculation on the cells that are in the same relative location. This is the default action of Excel. However, sometimes you need to lock in a cell reference to keep it from changing when the formula is copied. In this case, you need to use an absolute reference. When you apply a name to a range of cells, by default the name is an absolute reference to that range, as in our example of the formula for tax.

To change a cell reference from relative to absolute, you must enter the dollar sign symbol ($) in front of the column and row references. The shortcut for doing this: select the cell reference in the formula and press the F4 key, the relative/absolute/mixed reference toggle key. Lets say our business has pledged to give 11% of monthly profits to charitable causes. This percentage has been entered into E13. Lets compute the amount of charitable giving for each month.
Select cell H4 and enter =F4*E13. Copy the formula to H5:H6.

Because of relative referencing, both parts of the formula have been modified. But the second part of the formula needs to always point to cell E13. We can correct this by making it an absolute reference.
Select cell H4 and click on E13 in the formula bar. Press the F4 function key. The cell reference changes to $E$13. Now copy the formula to H5:H6 again.

This time the results are correct. When the formula in H4 is copied to H5, it becomes =F5*$E$13. The relative part of the formula is changed, but the absolute part still points to the cell containing the percentage.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 8

Of course, another way to solve the problem is to assign a range name to cell E13 and use it in the formula. Lets do that and apply the name to the formulas we have already created.
Click in cell E13. Click the Formula tab and select Define Name Excel suggests the name, Charitable_Giving, using the text in the adjacent cell.

Accept it by clicking the OK button.


Select the range H4:H6. Click the Formulas tab and select the Define Name drop down list and choose Apply

Names
Select Charitable_Giving from the Apply Name list and click OK.

The $E$13 reference is replaced in each of the formulas by the range name.

In rare instances, you might find that neither a relative nor an absolute reference will work properly when you copy the formulas. If the formulas refer to a range of values in a row or column, you might need to use mixed references. There are two types of mixed references: A$1 The column reference changes when the formula is copied to a new column, but the row reference always points to row 1 when the formula is copied to a new row. $A1 The column reference always points to column A when the formula is copied to a new column, but the row reference changes when the formula is copied to a new row.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 9

You can use the F4 key to toggle through all the reference types: relative (A1), absolute ($A$1), row absolute (A$1) and column absolute ($A1).

Converting formulas to values


Occasionally we want to replace a formula in a cell with the value the formula calculates. You can do this by using the Copy and Paste Special commands.
Click on the Cond Formatting worksheet. Select the range A3:D12. Each cell in this

range contains the formula =INT(RAND()*1000)+1. This formula returns a random number between 1 and 1000. (We will examine the formula in more detail in the section about functions.)
Because the RAND function is volatile, each time the worksheet is recalculated, a

new set of random numbers is generated. Press the F9 (Recalculate) function key several times to see how the cell values change. To freeze the current set of random numbers, we can replace the formulas with their current values.
With the range A3:D12 selected, click the Copy button. With the same range selected, go to the Home tab and select Paste, Paste Special.

(Or right-click on any cell within the selected range and select Paste Special from the shortcut menu.)
In the Paste Special dialog box, click the Values selection and then OK.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 10

Press Esc to remove the flashing marquee surrounding the selected range. The

formulas have been replaced by their values. Press F9 to see that the values no longer change when the workbook is recalculated.

Using formulas in conditional formatting


Conditional formatting is often used to modify the format of a cell based on the value in that cell. However, we can also use formulas to control conditional formatting. The formula must return a logical value of True (1) or False (0).

Now that we have converted the formulas in the Conditional Formatting worksheet to values, lets highlight all the values that are greater than the number in cell D1, which is initially set to 500.
Select the range A3:D12. Go to the Home tab and select Conditional Formatting, New Rule. Select from the list, Format only cells that contain Select the drop down that says below, and choose Greater than Tab to the condition box and click on cell D1 Click the Format button. This displays three of the Format Cells dialog box tabs. On

the Font tab, select Bold for the Font style and Red for the Color; click the OK button. The dialog box should look like the following figure.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 11

Click OK to apply the conditional formatting.

Excel changes the A3 relative reference in the formula for each cell in the range, while the $D$1 absolute reference forces each cell value to be compared with the value in D1. If the cell value is greater than that in D1, the formula returns the value True, and the bold red formatting is applied to the cell.
Change the value in D1 to another value between 1 and 1000, and the formatting

changes dynamically to highlight only those values that are greater than the selected value.
Change D1 to 1000. What happens? Why? Reset the value back to 500.

Function Basics
What is a function?
A function is a procedure that performs a commonly used calculation so the user doesnt have to recreate the formula for the calculation each time its needed. Excel contains more than 300 built-in functions. Many of these perform rather complex financial, mathematical or statistical calculations, while others assist the user in working with dates and times, text fields, logical decisions and table lookups.

Each function requires input values, which are called arguments. The number and types of arguments vary depending on the function.

A function can be entered as a formula by itself or as a part of a formula. Its format is the function name, followed by the arguments, which must be enclosed within parentheses and separated by commas. For example, =AVERAGE(B1:B10,D1:D10,F1:F10) This function calculates the average of the cell values in the three ranges B1:B10, D1:D10 and F1:F10. These three ranges are the arguments of the function.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 12

Categories of functions
The built-in functions are organized into the following 10 categories: Financial Date and Time Math and Trig Statistical Lookup and Reference Database Text Logical Information Engineering

In addition, you can create your own functions to perform complex calculations that are not covered by the built-in functions. These user-defined functions are created using Visual Basic for Applications. Other functions are available as add-ins from Microsoft and other software vendors. All of the engineering functions, many of the financial functions, and a few functions in the other categories are available only if the Analysis ToolPak add-in has been installed. To see if it is installed on your computer, select Tools, Add-Ins from the Excel menu, and look for a checkmark in front of Analysis ToolPak. Look up Analysis ToolPak in the Excel Help database for information about installing it. A list of the built-in functions is in the Appendix at the end of this manual. You can also get more information about functions in the Excel Help database. In Excel 2000, go to the Contents tab, click on the chapter Creating Formulas and select Using Functions. In Excel 2002/2003, go to the Help Table of Contents, select Working with Data and go to the Function Reference.

Entering functions
Functions can be entered manually by typing the entire function into the cell or the formula bar. Or you can type the function name and the left parenthesis in the cell and use the point-and-click method to select the cells that the function will use to perform the calculation.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 13

Tip: If you type a function name, enter it in lowercase. Excel automatically converts function names to uppercase. If the name remains in lowercase after you enter the formula, you know you have misspelled it! (In addition, Excel returns a #NAME? error in the cell if it doesnt recognize the entry as a function name or a range name.)

An easier way to enter a function is to select Formulas, Insert Function from the ribbon or click the Insert Function button located next to the Formula bar. The Insert
Function button

You can also use the keyboard shortcut SHIFT+F3 to initiate the Insert Function command.
Before we continue with the discussion of inserting functions, go to the Common

Functions worksheet, select cell A4, and click the Insert Function button.

When you select Insert Function, the Insert Function dialog box is displayed. (The dialog box looks a bit different in Excel 97/2000, but you use it in the same way.)

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 14

To select a function: 1. Select a category from the category drop-down list. The Most Recently Used category shows the last 10 functions that were used in Excel on your computer. All displays all the functions in alphabetical order. 2. Select the function name from the list in the bottom pane. The format and a brief description of the function are displayed below the pane. If you want more information about the function, click the Help link at the bottom of the dialog box. 3. Click the OK button to open the Function Arguments dialog box. This contains input areas for the arguments for the selected function.

The following figure shows the Function Arguments dialog box for the IF function.

To enter the arguments: 1. Arguments that are listed in bold type are required; the others are optional. When you click in an argument box, Excel displays a description of the argument. 2. You can type the arguments directly into the input boxes, or you

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 15

can enter cell references by selecting the cells or ranges on the worksheet. To get access to the worksheet, either drag the dialog box out of the way or click the collapse button at the right end of the argument input box. 3. As you enter arguments into the boxes, Excel displays the current values and the formula result. 4. When you have entered all the required arguments, click OK or press Enter to enter the function into the active cell.

Nested functions
Sometimes to get the result you want from your formulas, you will need to use a function as the argument of another function. This is called nesting functions. Excel allows up to 7 levels of nesting. The following formula contains two functions, AVERAGE and SUM, nested inside an IF function: =IF(AVERAGE(E7:E16)>4500,SUM(F7:F16),0) Notice that each function has its arguments enclosed in parentheses and separated by commas: the AVERAGE and SUM functions each contain one argument consisting of a range of cells; the IF function contains the two functions and the value 0 as its three arguments. (We will look at the IF function in more detail later.)

Editing functions
Functions can be edited like any other formula. But you can also use the Function Arguments dialog box to assist with viewing and editing the function. Select the function and click the Insert Function button to display the individual arguments in the Function Arguments dialog box.

If the formula contains nested functions, place the insertion point within the function name in the formula bar to display the arguments for that function. For example, the following function arguments dialog box is displayed if we select the IF function in the example above and click the Insert Function button.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 16

Working with Functions


Throughout the rest of the class, we will look at a number of functions from different categories and experiment with them to perform common operations.

Common Math and Statistical functions


The most common functions in most Excel worksheets are those that perform simple mathematical and statistical operations, such things as summing a range of values, determining the maximum and minimum values, and counting occurrences of different types of values. We will enter several of these functions on the Common Functions worksheet.

The SUM function


Format: SUM(number1, [number2], )

Excel makes it very easy to insert a SUM function by using the AutoSum button on the Standard toolbar. In Excel 2002/2003 a drop-down arrow has been added to the AutoSum button to provide the same easy access to the AVERAGE, COUNT, MAX and MIN functions as well.
The AutoSum button

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 17

Select cell B18 and click the AutoSum button. Excel looks at the surrounding cells

and suggests that we sum B7:B17, which is exactly what we want. Press Enter to insert the function. (The blank cell in B17 will not affect the sum. As a matter of fact, having a blank cell at the bottom of the range will make it easier for us to insert additional rows and have them automatically included in the sum.)

We could copy the formula in B18 to C18:E18 to sum the columns for the other quarters. However, we can create many totals at one time by selecting the ranges to be summed, including the blank cells where the SUM functions are to be inserted.
Select the range B7:F18 and click the AutoSum button. Excel automatically sums all

the rows and columns and inserts a grand total in F18.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 18

The AVERAGE, MAX and MIN functions


Format: AVERAGE(number1, [number2], ) MAX(number1, [number2], ) MIN(number1, [number2], ) The AVERAGE, MAX and MIN functions are in the Statistical category of functions. There are two versions of each of these functions. The difference is in the cell values that are included in the calculation. AVERAGE, MAX and MIN perform their operations on numeric values only; while AVERAGEA, MAXA and MINA include text and logical values in addition to numeric values. AVERAGE and AVERAGEA compute the average, or arithmetic mean, of the values in the selected range(s). The MAX and MIN functions return the maximum and minimum values in their ranges. Lets look at some examples of these functions.
Select cell B19, click the Insert Function button, and select AVERAGE from the

statistical category.
Replace the suggested range in the Number 1 argument with the range B6:B17 and

click OK.
Copy the formula in B19 to cell B20 and change it to AVERAGEA with the same

range. (Press Ctrl+, click after the E in AVERAGE and type A, press Enter.) The result in B19 is $179.9, the sum of the column divided by the 10 numeric entries in the range. But the value in B20 is $163.5, because the AVERAGEA function includes the non-blank B6 cell and divides the sum by 11!
Copy the functions in B19:B20 to C19:F20. In cells B21:B24, insert the functions that are listed in column A, using the range

B6:B17.
Copy B21:B24 to C21:F24.

There are no surprises here except for the zero values in D24 and F24. This is a result of including the text cells in row 6, which evaluate to zero.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 19

The COUNT functions


Format: COUNT(value1, [value2], ) COUNTBLANK(range) COUNTIF(range, criteria) Another common operation in worksheets is counting the number of cells that meet certain conditions. The counting functions are in the Statistical category and include COUNT, COUNTA, COUNTBLANK and COUNTIF.

These have already been entered on the worksheet in C28:C30 and G28:G30. The range A6:G16 has been given the name DataRange to simplify the formulas.

Here is a description of the functions in these cells:


C28: =COUNT(DataRange) - Counts the numeric cells in the range. C29: =COUNTA(DataRange) - Counts the non-blank cells in the range. C30: =COUNTBLANK(DataRange) - The number of blank cells. G28: COUNTIF(DataRange,=0) COUNTIF counts cells based on a single

criterion, which is entered as a second argument, in this case =0. The result is the total number of cells in the range that have the value zero.
G29: COUNTIF(DataRange,>0) - Now the function counts the total number of

cells with positive values.


G30: COUNTIF(DataRange,*) - This counts the total number of text cells. The * is

a wildcard, which represents any text characters.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 20

Averaging non-zero values


Now that we know how to count various types of cells, lets take another look at the AVERAGE function we entered earlier. AVERAGE includes all the numeric values in the range, including any zeros. But sometimes this gives a different number than we want. In our example, we want the average sales of all our salespeople. But not all the salespeople worked the entire year. One way to fix this is to delete the zero values in the cells for those salespersons. But by using the SUM and COUNTIF functions, we can compute the average of the non-zero sales.
In cell B25 enter a SUM function to total the range B7:B17. Click at the end of the formula in the Formula Bar and type the divide operator, /. Now click the Insert Function button and select COUNTIF from the Statistical

category.
Enter B7:B17 for the Range and >0 for the Criteria and click OK. The result is the

average of the non-zero values in the range.


Copy the formula in B25 to C25:F25.

Using SUM to calculate a running total


Another interesting use of the SUM function is the calculation of a running total.
Select the Checkbook worksheet. In cell E3 enter =SUM($D$3:D3). (Shortcut method: click the AutoSum button, click

cell D3, press the F4 function key, type a colon and click cell D3.
Copy this formula down through cells E4:E9.

Excel adjusts the relative part of the range reference in the formulas to sum the values in column D from cell D3 down to the current row.

The SUMIF function


Format: SUMIF(range, criteria, [sum_range])

The SUMIF combines the action of SUM with a condition to determine which cells in the range are to be summed. It takes three arguments: the range in which to look for the

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 21

condition, the condition itself, and the range to be summed. Two SUMIF functions have been entered in the Checkbook worksheet:
D12: =SUMIF(C4:C10,Deposit,D4:D10) - The value is the total of all cells in

D4:D10 for which the corresponding cells in C4:C10 contain the value Deposit.
D13: =SUMIF(C4:C10,<>Deposit,D4:D10) This totals all payments, those cells

that are not deposits. (The dual operator <> means not equal.)

The RAND and INT functions


Format: RAND() INT(number) In an earlier section, we saw how to replace a formula with its value. The formula in that example used two other Math & Trig functions, INT and RAND.
Select the Cond Formatting worksheet and click cell A16.

The formula in this cell, =INT(RAND()*1000)+1, results in a random number between 1 and 1000. Heres how it works: The RAND function returns a random number greater than 0 and less than 1. Notice that it does not have any arguments, but the parentheses are still required. This number is multiplied by 1000, and the fractional part is removed by the INT (integer) function, to give a number between 0 and 999. 1 is added to this number, resulting in a number in the range of 1 to 1000.

The RAND function is a volatile function, which means it is recalculated each time the workbook is opened or the worksheet is recalculated. Press the F9 function key several times to recalculate the sheet and see the resulting random numbers.

The MOD and ROW functions


Format: MOD(number, divisor) ROW([reference]) While we are in this worksheet, lets revisit conditional formatting and use another Math & Trig function, MOD, along with ROW from the Lookup & Reference category, to highlight every other row of the range with a fill color.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 22

Select the range A3:D12. Go to the Home tab and select Conditional Formatting, New Rule From the list, select Use a formula to determine

which cells to format


In

the

formula

box,

type

the

formula

=MOD(ROW(),2)=1.
Click the Format button and select the Patterns

tab. Select a light color to fill the cells that meet the condition.
Click OK twice to return to the worksheet. Deselect

the selected range to see the effect. The ROW function returns the number of the row the cell is in. The MOD function divides this number by its second argument, in this case 2, and returns the remainder. If its an odd-numbered row, the remainder is 1, and the formula evaluates to 1=1, which is true. (Remember that formulas in conditional formats must return a logical value.) Therefore, the cell is filled with the color you selected. If its an even-numbered row, the formula evaluates to 0=1, which is false, and the conditional formatting does not apply. So why arent all the cells in the odd numbered rows filled with the selected color? Since two conditions have been set for this range, the first to be satisfied is the one that determines the formatting for the cell. So any cell that has a value greater than the value in D1 has the bold red font applied, and the other condition is not even considered. If you set the value in cell D1 to 1000, the effect of the first condition is removed, because none of the numbers can be greater than 1000.

3-Dimensional formulas
A reference that refers to the same cell or range on multiple worksheets is called a 3-dimensional reference. This type of reference defines a worksheet range, naming the starting and ending worksheets, and a cell range within the worksheets. For example, the formula =SUM(Sheet1:Sheet3!D15) sums the values in D15 on all the

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 23

worksheets from Sheet1 through Sheet3. Several of the functions, including SUM, can accept 3-D references as their arguments. To create a 3-dimensional formula: 1. Select the cell on the worksheet for the 3-D formula. Start the formula, by typing it manually or by inserting a function. 2. Click on the first worksheet tab to be included in the range. 3. Hold down the shift key on the keyboard and click on the last worksheet tab to be included in the range. Release the shift key. 4. Select the cell or range of cells to be included in the formula. 5. Press Enter to complete the formula.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 24

Lets look at a common use of 3-D references, summarizing data from multiple worksheets onto a single sheet.
Look at the East Sales, Midwest Sales, West Sales and Sales Summary

worksheets. The first three sheets contain the sales data for the four quarters of the year for each of our companys three regional divisions. We will summarize the sales on the fourth sheet. Since all four sheets were created from the same template, the values are in the same location on each sheet.
Select the Sales Summary worksheet and click in cell C7. We will build a 3-D

formula in this cell and copy it to the rest of the range.


Click the AutoSum button to initiate the SUM function. Click on the East Sales worksheet tab to add it to the formula. Hold down the Shift key and click on the West Sales tab to complete the worksheet

range. Release the shift key.


Finally click on cell C7 to add it to the formula. Press Enter. Select C7 and copy the formula to C8:C9 and then copy C7:C9 to D7:F9.

The Sales Summary sheet now contains the totals for all three divisions. It will be updated automatically if any changes are made to the values on the other sheets.

Financial functions
Financial functions perform common business calculations, such as determining the payment for a loan, the future value or net present value of an investment, and the values of bonds or coupons.

Common arguments for the financial functions include: Future value (Fv) The value of the investment or loan after all payments have been made. Number of periods (Nper) The total number of payments (periods). Payment (Pmt) The amount paid periodically to an investment or loan.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 25

Present value (Pv) The value of an investment or loan at the beginning of the investment period. For example, the present value of a loan is the principal amount that is borrowed.

Rate (Rate) The interest rate or discount rate for a loan or investment. Type (Type) The interval at which payments are made during the payment period, i.e., at the beginning of the month or end of the month.

The PMT function


Format: PMT(rate, nper, pv, [fv], [type])

Select the Financial worksheet.

Lets look at one of the most-used financial functions, PMT, the periodic payment for a loan or investment. In this example, we are borrowing $10,000 (C3) at an annual interest rate of 5.5% (C4), to be paid back in equal installments over 36 months (C5).
In cell C6 insert a PMT function to calculate the monthly loan payment. The PMT function requires three values, which are entered in cells C3:C5. In the

Function Arguments dialog box, enter the following arguments: o Rate: C4/12 Since we are calculating monthly payments, we must divide the annual interest rate by 12 to specify a monthly interest rate. o Nper: C5 This is already expressed in months. If we had entered it as 3 years, we would have to multiply it by 12 to get the number of months. o Pv: C3 The amount being borrowed. The Function

Arguments box should look like the following picture.


Click OK to enter the function.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 26

The resulting payment is displayed as a negative amount. We usually format the cell as currency with parentheses around negative numbers to indicate that it is a debit. To display it as a positive number, simply edit the formula and put a negative sign in front of the Pv argument.

The other PMT-related functions


Format: PPMT(rate, per, nper, pv, [fv], [type]) IPMT(rate, per, nper, pv, [fv], [type]) RATE(nper, pmt, pv, [fv], [type] NPER(rate, pmt, pv, [fv], [type]) PV(rate, nper, pmt, [fv], [type]) The five functions listed above are all related to the calculation of monthly payments. These functions have been entered on the Financial worksheet.

The table below the loan calculations displays the principal and interest payments for the first two and the last two periods of the loan. These values are calculated by using the PPMT and IPMT functions, which have an additional argument, Per, the payment period number. The table could be expanded into a full amortization schedule showing the payment details for all the payment periods of the loan.

If we know the values for any three of the arguments for the monthly payment functions, we can calculate the fourth value by using the functions RATE, NPER and PV as displayed in the formulas in cells F3, F4 and F5.
Try modifying any of the values in C3, C4 or C5 to see the resulting monthly

payment. The changes will also be reflected in the amortization table.

Data tables
A Data Table provides a more effective way to compare the results of a formula when changes are made to its arguments. The data table calculates multiple versions of the formula and displays the results side-by-side. Tables can be set up as row-oriented or column-oriented with one or two variables.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 27

You can view an example of a data table starting at row 18. This is a one-variable column-oriented table, which compares the monthly payment, total payments and total interest paid for five different interest rates.

In the picture above, the formula in cell D25 is displayed. This is called an array formula, because it operates on an array of cells. The same formula is entered in every cell in the range B21:D25. (We will look at array formulas in a later section.) See Data Table in Excel Help for information about how to create these tables.

Goal Seek
Lets say we know the monthly payment we can afford and we want to find out how much we can borrow. We could use the PV function to calculate this. But we can also work the PMT function backwards by using the Goal Seek tool.
Click on cell C6 (the cell that contains the PMT formula) and select Data, What-if

Analysis, Goal Seek from the menu. The Goal Seek dialog box is displayed:

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 28

The Set cell field displays the address of the active cell. We tell Goal Seek to attempt to set this cell to the value we enter in the To value field by changing the value in the cell in the By changing cell field.
Enter 250 and $C$3 in these two fields and click OK.

Goal Seek attempts to find a value for the loan amount that will result in a $250 payment for the interest rate and payment period we have specified. If its successful, the Goal Seek Status box will tell us it found a solution, which it displays in cell C3. Otherwise, it will return the message May not have found a solution. In this example, Goal Seek is successful and returns a value of $8,279 for the loan amount. All the other formulas on the worksheet are recalculated at the same time to reflect the new loan amount.
To save the new data, click OK. To set it back to the previous values, click Cancel.

Date/Time functions
Excel handles dates and times in a special way. Dates are stored as serial numbers that represent the number of days that have elapsed since January 1, 1900. (Actually, its off by one day! Excel followed the same date numbering system that was established by Lotus 1-2-3, which mistakenly assumed 1900 was a leap year and added an extra day.) For example, 01/01/1900 = 1, 01/01/2000 = 36526, and 12/31/9999 (the largest date Excel can handle) = 2,958,465.

Times are stored as fractions, representing the amount of the day that has elapsed: midnight is 0.0, 6:00 AM is 0.25, 6:00 PM is 0.75, etc. Storing dates and times as numbers in this fashion makes date and time calculations simple. It also allows us to store a date and time in one number, the integer portion representing the date and the decimal portion representing the time.

You should always use the Date and Time number categories (not Text) when you enter dates and times so Excel will store them as date/time serial numbers. Then you can select the specific display type format you want. If you enter a recognizable date (with dashes or slashes between the parts) or time (with colons) into a cell with the default General format, Excel will set the cell format to the Date or Time category.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 29

Date/time stamps and the NOW and TODAY functions


Format: NOW() TODAY() Current date stamp: Ctrl+; Current time stamp: Ctrl+Shift+:

Lets look at two ways to insert the current date and time into a worksheet. Then well view the date and time serial numbers.
Select the Date and Time worksheet. Select cell B4 and insert todays date using the date stamp keyboard shortcut,

CTRL+;
Select cell B5 and insert the current time using the CTRL+SHIFT+: shortcut.

The date and time stamps enter a static date and time that will not change when the workbook is saved and reopened. You can also enter the current date using the NOW and TODAY functions. But unlike the date/time stamps we used above, this date is volatile; it is updated each time the worksheet is recalculated. TODAY returns just the date; NOW returns the date and time. These are among the rare functions that do not require an argument, but you must include the parentheses.
In cell B6 enter the function = TODAY () In cell B7 enter = NOW () Also enter =NOW() in cell B8. Right-click the cell and select Format Cells. On the

Number tab, select the Time format 13:30 to display the time without the date.
Select the range B3:B8, and copy the selection to C3:C8. If you use the fill handle to

copy, select Copy Cells from the Auto Fill Options smart tag menu.
Select C3:C8, right-click on the selected range and select Format Cells. On the Number tab, select General and click OK. The values you see in the cells are

the serial numbers that Excel stores to represent the date and time.
Press the F9 key to recalculate the worksheet. The time part of the NOW function

is updated to reflect the new current time, while the time in C5 remains unchanged.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 30

Date calculations and functions


Format: DATE(year, month, day) DATEVALUE(date_text) DAY(serial_number) MONTH(serial_number) YEAR(serial_number) WEEKDAY(serial_number, [return_type]) Since dates and times are stored as numbers, date/time calculations are very simple. The remainder of the worksheet demonstrates some of the calculations you can perform with dates.
B11: =B6+180 Calculates the date 180 days from the current date. B12: =12/25-B6 - Subtracts todays date from December 25 (it defaults to the

current year) to display the number of days until Christmas! The following calculations use some of the date functions: DATE create a serial number date from three arguments for the year, month and day. DATEVALUE converts a date that has been entered as text into a serial number date. DAY, MONTH and YEAR return the respective parts of the date from a serial number date. WEEKDAY returns the number of the day of the week, where Sunday = 1 through Saturday = 7. (Other numbering schemes are available by using the optional return_type argument.)
B13: =WEEKDAY(B6) Displays the day number of the week for todays date. B14: =B6-DATE(YEAR(B6),1,0) This formula computes the Julian date (the

number of the day in the year). The DATE function creates a serial date for January 0 of the current year, which is also December 31 of the previous year!
B15: =DATE(YEAR(B6),12,31)-B6 This formula calculates the flip side of the

Julian date, the number of days remaining in the year.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 31

B16: =DATE(YEAR(B6),MONTH(B6)+1,0) This bizarre formula calculates the last

day of the month. It takes advantage of the fact that the last day of the current month is equal to the 0th day of the next month!

Using AutoFill with dates


Excel includes a feature called AutoFill, which gives us a very quick way to create a series of numbers, dates, times and other items. (See AutoFill in Excel Help for more information about this feature.) Heres an example, showing how to create a list of dates for the last day of each month of the current year.
In cell D4 enter 1/31/yy (yy is the last two digits of the current year). Then click the fill

handle and drag down through cell D15. Release the mouse button and select Fill Months from the Auto Fill Options smart tag menu. We can also use formulas to generate a series of dates.
In cell E4 enter todays date. In cell E5 enter the formula =E4+7 and copy the formula down through cell E15. The

result is a list of dates for this day of the week for the next 11 weeks.

Time calculations and functions


Format: TIME(hour, minute, second) TIMEVALUE(time_text) HOUR(serial_number) MINUTE(serial_number) SECOND(serial_number) Time calculations work in a similar way. You can simply subtract one time from another to get elapsed time, or add times to calculate accumulated time. For an example of working with time values, look at the section of the worksheet below row 18.
The formula in B20 adds the number of hours in B19 to the current date/time from

the NOW function. The TIME(B19,0,0) function converts the raw number in B19 to a time serial number. This conversion would not be required if the value in B19 had been entered as a time value, such as 12:30 for 12.5 hours.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 32

The formula =C23-B23 in D23 simply subtracts the start time from the end time to

give elapsed time.


The formula in D24 handles those situations where the end time is less than the start

time; i.e., we have passed midnight and are now into the next day. The +(C24<B24) part of the calculation is a logical expression that evaluates to True (the value 1) when this condition occurs. This adds 1 day to the formula (in time serial numbers, 1.0 = 24 hours).
The SUM in D26 totals the elapsed times in D23:D25. However, if the total adds up

to more than 24 hours, you wont get the correct answer! In order to display a time greater than 24 hours, use the custom format [h]:mm.
Cell D27 displays the same total time as a decimal number by multiplying D26 by 24.

Text functions
Format: UPPER(text) LOWER(text) PROPER(text) LEN(text) LEFT(text, [num_chars]) RIGHT(text, [num_chars]) MID(text, start_num, num_chars) TRIM(text) TEXT(value, format_text) VALUE(text) The text functions allow you to manipulate text strings. A common operation with text strings is concatenation, joining two text strings to form a single string, using the concatenation operator, &.
Select the Text worksheet. In cells C4, D4 and E4 enter your first name, middle name/initial and last name. In cell C5 enter the following formula: =C4&" "&D4&" "&E4 (with spaces between

each of the double quotes). This formula concatenates the parts of your name, separated by spaces, into a single value.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 33

The rest of the worksheet contains examples of: Changing the case of the text string using the UPPER, PROPER and LOWER functions. Determining the number of characters in the text string with the LEN function. Extracting parts of a text string using the LEFT, RIGHT and MID functions. Removing extra spaces from the text string with the TRIM function. Converting numbers to text and text to numbers using the TEXT and VALUE functions.

Logical functions
Using the IF function to make decisions
Format: IF(logical_test, [value_if_true], [value_if_false])

Logical functions are used to test conditions and to make decisions based on the result of the test. The most-used logical function is the IF function. Other formulas and functions are often nested within the IF function to perform different calculations based on the result of the logical test.
Select the Logical&Lookup worksheet.

This worksheet is an order entry form for Fruits2Go, a fruit basket mail order business that serves the 4-state area of Illinois, Wisconsin, Indiana and Michigan. The worksheet has already been set up with formulas to do some of the calculations. We will use some of the logical and lookup functions to complete the missing calculations for the volume discount, state tax and shipping charges.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 34

We give our customers a volume discount of 15% for orders over $250. We will use an IF function to determine if an order qualifies for the discount.
In cell F16 insert an IF function (found in the Logical category). Enter the following arguments:

o o

Logical_test: F15>250 Value_if_true: -F15*0.15 This computes the 15% discount. Make it a negative value to show that its a discount and so the SUM function in the Total Charge cell will work correctly.

o o

Value_if_false: 0 Click OK to enter the formula.

Test the formula by adjusting the quantities in B11:B13 to get an order total greater

than $250.

Nested IF functions
Now lets say we have decided to extend the discount program to give a 10% discount for orders over $100. This calculation requires a nested IF. We will replace the Value-iffalse part of the first IF function with a second IF to test for the new condition.
Select cell F16 and click the Insert Function button to display the IF Function

Arguments dialog box. Highlight the 0 in the Value_if_false box.


To insert another IF function, select IF from the function list that overlays the Name

box. (It should be the first function in the list; if not, click the drop-down arrow to see additional functions.) This opens a new IF Function Arguments dialog box. Enter the following arguments: o o o o Logical_test: F15>100 Value_if_true: -F15*0.1 Value_if_false: 0 Click OK to enter the formula.

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 35

Heres the resulting formula: =IF(F15>250,-F15*0.15,IF(F15>100,-F15*0.1,0)). (Notice the double right parentheses at the end of the formula. The first right parenthesis closes the nested IF; the second closes the original IF.)
Test the formula by changing the quantities in B11:B13. What is the result when the order total is exactly $100 or $250? How could you change the formula so the discounts kick in at the $100 and $250

amounts?
What if we wanted to give the customers a 5% discount for orders over $75?

2012 DCG Technology Learning Center

Excel Basic Functions & Formulas - Page 36