Spreadsheet Functions - Libnet...5 * Functions If you want a spreadsheet to calculate always using...

22
1 * Class Description This is an introduction to the use of functions in spreadsheets, with a focus on Microsoft Excel and Google Drive Spreadsheets. The main topics are arithmetic calculations and order of precedence; working with dates and times; some of the most commonly used functions (SUM, AVERAGE, MAX, MIN, IF); and named ranges. All ages are welcome. Class Length One and onehalf (1½) hours Introduction After word processing, spreadsheets are probably the most important and widespread computer application. In fact, the first two ‘killer applications’ (an application regarded as so necessary or desirable that it sells the larger product which it uses) for personal computers were spreadsheet applications: VisiCalc for the Apple II and Lotus 123 for the IBM PC. Originally designed to replace accountants’ columnar paper, spreadsheets have become the norm wherever tabular data needs to be built, organized, and shared. Modern spreadsheets have hundreds of functions available to perform almost any imaginable calculation – far too many to cover in this brief session. In fact, forty hours of classes would not be sufficient to cover all the functions. But most users have no need for more than a handful of functions. They learn the functions they need and ignore the rest. The goal here is to understand how functions work, how to use them, how to discover other functions, and how to apply the understanding of functions to newly found functions. This class is targeted at users with at least a basic knowledge of spreadsheets and is intended to provide an introduction to using functions and creating formulas. The focus is on Microsoft Excel and Google Drive Spreadsheets, but the lessons can be applied to other spreadsheet applications. Objectives Learn how functions work Learn how to use functions Learn how to find functions Learn how to build formulas This manual is a handout for you to keep. Please feel free to use it for taking notes. Before We Begin: Please open Microsoft Excel and, if you wish, open Google Drive (drive.google.com). If you don’t already have a Google account, you can go to accounts.google.com/SignUp and register an existing email address (click on the I prefer to use my current email address link) or create a free gmail.com address; or, if you prefer, ask for the User ID and password for one of the genevalibraryclass(number)@gmail.com accounts — (please don’t change the password!). If you want to do the exercises in just Google Drive Spreadsheets, that is fine; if you want to do the exercises in just Microsoft Excel, that is also okay. Spreadsheet Functions

Transcript of Spreadsheet Functions - Libnet...5 * Functions If you want a spreadsheet to calculate always using...

  •   1  * 

    ClassDescriptionThis is an introduction to the use of functions in spreadsheets, with a focus on Microsoft Excel and Google Drive Spreadsheets. The main topics are arithmetic calculations and order of precedence; working with dates and times; some of the most commonly used functions (SUM, AVERAGE, MAX, MIN, IF); and named ranges. All ages are welcome. 

    ClassLengthOne and one‐half (1½) hours 

    IntroductionAfter word processing, spreadsheets are probably the most important and widespread computer application. In fact, the first two ‘killer applications’ (an application regarded as so necessary or desirable that it sells the larger product which it uses) for personal computers were spreadsheet applications: VisiCalc for the Apple II and Lotus 1‐2‐3 for the IBM PC. 

    Originally designed to replace accountants’ columnar paper, spreadsheets have become the norm wherever tabular data needs to be built, organized, and shared. 

    Modern spreadsheets have hundreds of functions available to perform almost any imaginable calculation – far too many to cover in this brief session. In fact, forty hours of classes would not be sufficient to cover all the functions. But most users have no need for more than a handful of functions. They learn the functions they need and ignore the rest. The goal here is to understand how functions work, how to use them, how to discover other functions, and how to apply the understanding of functions to newly found functions. 

    This class is targeted at users with at least a basic knowledge of spreadsheets and is intended to provide an introduction to using functions and creating formulas. The focus is on Microsoft Excel and Google Drive Spreadsheets, but the lessons can be applied to other spreadsheet applications. 

    Objectives Learn how functions work  Learn how to use functions  Learn how to find functions  Learn how to build formulas 

    Thismanualisahandoutforyoutokeep.Pleasefeelfreetouseitfortakingnotes.

    BeforeWeBegin:Please open Microsoft Excel and, if you wish, open Google Drive (drive.google.com). If you don’t already have a Google account, you can go to accounts.google.com/SignUp and register an existing e‐mail address (click on the I prefer to use my current email address link) or create a free gmail.com address; or, if you prefer, ask for the User ID and password for one of the genevalibraryclass(number)@gmail.com accounts — (please don’t change the password!). 

    If you want to do the exercises in just Google Drive Spreadsheets, that is fine; if you want to do the exercises in just Microsoft Excel, that is also okay. 

    Spreadsheet Functions

  •   2  * 

    Workingwithdates&timeWhen Lotus 1‐2‐3 introduced date calculations, it made a blunder: it programmed the year 1900 as a leap year. It wasn’t. It numbered 1 Jan 1900 as 1, 2 Jan 1900 as 2, and so forth. 28 Feb 1900 was numbered 59, the non‐existent 29 Feb 1900 was numbered 60, and 1 Mar 1900 became 61. By the time the error was noticed, many spreadsheets were using date calculations so the mistake was never fixed. Subsequent spreadsheet programs, in order to preserve compatibility with existing spreadsheets, handle this in different ways. Microsoft Excel simply copied Lotus 1‐2‐3: dates prior to 1 Mar 1900 are incorrect, and it cannot handle any date prior to 1 Jan 1900. Google Drive Spreadsheets made 30 Dec 1899 a 0 which makes all dates calculate correctly, but makes it incompatible with Microsoft Excel and Lotus 1‐2‐3 for dates prior to 1 Mar 1900. Some spreadsheets, (e.g. the Calc application in LibreOffice, Apache OpenOffice, or NeoOffice) make 30 Dec 1899 a 0 and dates prior to that negative values (it can handle dates back to  — historians and genealogists, take note! — 1 Jan 0001). 

    The good news? Most of us have no need to calculate with dates that long ago and we can ignore these details. However… 

    Macs: the 1904 system. Spreadsheets built for the earliest Macintosh computers used a similar system, but began with 1 Jan 1904. Spreadsheets for modern Macs still use this system, including Excel.  When exchanging spreadsheets with Mac users, if your dates are off by four years and one day, you’ll need to take these steps. 

    Click on the File tab.

     

    This opens the ‘Backstage’. Click on Options. This opens the Excel Options dialog box. Click on Advanced. 

     

     

     

     

     

     

     

     

     

     

       

  •   3  * 

    Scroll nearly all the way to the bottom and find the section labelled When calculating this workbook: and place a check (by clicking on the box) next to ‘Use 1904 date system’. 

    Click the OK button and everything should be correct. 

    You can also take these steps with a spreadsheet you plan to share with a Mac user. 

     

    Since each day is calculated as a whole number, times are calculated as fractions: half‐way through the day (12 noon) is 0.5; one‐quarter through the day (6:00 a.m.) is 0.25; three‐quarters through the day (6:00 p.m.) is 0.75. All times are calculated in this manner. 

    Let’s do some calculations with dates. 

    MicrosoftExcel 

    1. Enter a date in the past in one of the cells.  

    2. Enter today’s date in a different cell. 

    3. Move to a third cell and 

    a. Press = (equal sign) – this tells Microsoft Excel you want a calculation done (a formula). 

    b. Move to the cell with the later date using either the arrow keys or by clicking on the cell with the mouse. 

    c. Press - (minus sign). d. Move to the cell with the earlier date. 

    e. Either click the ✓ between the Name Box and the Formula Bar or press J. 

    The result is the number of days between the two dates. 

    4. Move to a fourth cell and enter a whole number. 

       

    Current Date Shortcut:

    F+; Current Time Shortcut:

    FH+:

    As soon as you press the equal sign, the area between the Name Bar and the Formula Bar 

    changes: 

    adding an ✗ (cancel), ✓ (OK / J) and an (link to functions).

  •   4  * 

    5. Move to a fifth cell and 

    a. Press = (equal sign). b. Move to the cell with today’s date. 

    c. Press + (plus sign). d. Move to the fourth cell (the one with the whole number). e. Either click the ✓ between the Name Box and the Formula Bar or press J. 

    The result shows what the date will be in the number of days you entered in the fourth cell. 

    GoogleDriveSpreadsheets 

    1. Enter a date in the past in one of the cells. 

    2. Enter today’s date in a different cell. 

    3. Move to a third cell and 

    a. Press = (equal sign) – this tells Google Drive Spreadsheets you want a calculation done (a formula) and the top level items in the menu will grey out. 

    b. Move to the cell with the later date using either the arrow keys or by clicking on the cell with the mouse. 

    c. Press - (minus sign). d. Move to the cell with the earlier date. 

    e. press J. The result is the number of days between the two dates. 

    4. Move to a fourth cell and enter a whole number. 

    5. Move to a fifth cell and 

    a. Press = (equal sign). b. Move to the cell with today’s date. 

    c. Press + (plus sign). d. Move to the fourth cell (the one with the whole number). e. press J. 

    The result shows what the date will be in the number of days you entered in the fourth cell. 

       

    Current Date Shortcut:

    F+; Current Time Shortcut:

    FH+:

  •   5  * 

    FunctionsIf you want a spreadsheet to calculate always using the current date, it would be quite inconvenient to have to open a spreadsheet and manually replace dates. It would be a lot more convenient to have the spreadsheet automatically use the current date. That is where one turns to functions. 

    Functions are preset formulas and, like all formulas, they begin with the equal sign. Following the equal sign is the function name; followed by an opening parenthesis, then arguments (zero or more, separated by commas), and completed with a closing parenthesis – like this: 

    =FUNCTION(argument1,argument2,argument3,…) 

    TODAYfunctionMicrosoftExcel

    1. In Microsoft Excel, switch to the Formulas Ribbon: 

    2. Since a formula for today’s date is obviously a Date & Time function, click on the Date & Time icon to reveal a list of date and time functions: 

    3. Move the mouse down to TODAY and click on it. (Note: when hovering [before clicking] over a function, a pop‐up appears explaining what the function does.) 

    This will produce a Function Arguments dialog box: 

     When a function requires arguments, they will be displayed in the dialog box with a place to provide the information. The TODAY function has no arguments, so there are no fields to be 

    completed. The Function Arguments dialog box displays the result, but here we see the result is ‘Volatile’ – not to worry, it just means the result is changeable – which is exactly what we want, something that changes as the date changes. All Function Arguments dialog boxes include a link for Help on this function which will open a detailed explanation of the selected function, its arguments (if any), and examples. This is a gold mine of information. 

    In both the active cell and in the Formula Bar we should see =TODAY(). This follows the format explained above, with nothing between the parentheses because this function has no arguments. 

    4. Either click the OK button of the Function Arguments dialog box or click the ✔ between the Name Box and the Formula Bar or press J to complete the formula. 

     

     

     

     

  •   6  * 

    GoogleSheets 

     

     

    In Google Drive Spreadsheets, there are two ways to access functions: (1) from the 

    menu (Insert, Function, [SUM, AVERAGE, COUNT, MAX, MIN functions] More [to access 

    other functions]); and (2) from the icon bar (SUM, AVERAGE, COUNT, MAX, MIN 

    functions and More functions…). 

    Both the More from the menu and the More functions from the icon bar open a new web page… 

       

    To create a Google Drive Spreadsheet: log in to Google Drive, click on Create to open the drop‐down men, then click on Spreadsheet.  

     

  •   7  * 

    The core of this page is a table with columns for Type (Google’s categories), Name (of the function), an unlabelled column which shows the function with its arguments, and Description. Each column can be sorted (A→Z or Z→A). Just above the table is a drop‐down menu which can be used to select a single category of functions or all categories of functions. 

     

     

     

     

     

     

     

     

     

     

     

     

     

    Use the drop‐down (Narrow by…) menu … 

     

     

    … to display only Date functions (which include Time functions), 

     

    … then scroll down until you find the TODAY function (next page). 

       

    Narrow by: You can enter keywords into the box and the most likely functions will appear. It can be used in conjunction with the drop-down menu or in place of it.

  •   8  * 

     

     

    Unfortunately, there is no way to select a function and insert it into a formula. You can copy a function’s name and paste it into a formula. 

     

    Don’t forget you can use F+F to search the text on the web page. 

     

     

       

    Entering Functions Directly (both Microsoft Excel and Google Sheets): Once you become familiar with a formula, you’ll probably want to just enter it directly into a cell, bypassing all the other steps. To enter

    the TODAY function, type =TODAY()J As you begin to type, both Google Drive Spreadsheets and Microsoft Excel pop up a tiny message to assist you.

    In Google Drive Spreadsheets, pressing J will insert the function and move you to the first argument. In Microsoft Excel, you need to use the mouse to double-click on the popup.

  •   9  * 

    SUM,AVERAGE,COUNT,MAX,andMINfunctions1. In Google Drive Spreadsheets, enter several random values in a column and copy all to at least seven or eight 

    other columns. You should have something like this: 

    2. Move to the first empty cell just beneath the first column of numbers. 

     

    3. Using either the menu or the icon bar, select the SUM function. You should see something like this: 

     

    4. Select the cells containing the values in the column above the cell in which you are 

    working. (Be sure not to select the cell you 

    are using to insert the formula.) The formula 

    should appear both in the cell and in the 

    formula bar: 

     

     

    5. Press J to complete the formula. 6. Use the other four functions which are always visible 

    (AVERAGE, COUNT, MAX, MIN) for each of the other four columns. 

    7. Highlight another column of numbers and then select the SUM function. 

     

    8. A formula will appear in the cell beneath the column of values: 

    9. Press J to complete the formula. 

       

    There are two ways to select the

    cells: click and drag over the cells

    with the mouse; or use the arrow

    keys to move to one end of the

    cells to be selected, press and hold

    H, and use the navigation keys to move to the opposite end.

  •   10  * 

    10. Highlight a row of numbers and then select one of the always visible functions. 

     

     

    11. A formula will appear in the cell to the right of the row of numbers: 

    12. Press J to complete the formula.  

     

    13. Finally, select a block of values and select one of the always visible functions. 

    14. A formula will appear in the cell immediately beneath the first column of values (note: it will 

    replace anything already there!). 

     

    15. Press J to complete the formula.  

     

    Do you have something like this? 

     

       

  •   11  * 

    Copy one of the columns from the Google Drive Spreadsheet we just used to a Microsoft Excel spreadsheet. (You can include the calculation result at the bottom of the column, if desired, but it will copy as a number, not a formula.) Then copy those numbers to some additional columns. You should have something like this: 

    Before continuing, here is a closer look at Microsoft Excel’s FORMULA ribbon. 

     

    Excel’sFunctionLibraryThe leftmost group is the Function Library. Its icons are Insert Function 

    which opens this dialog box: 

    The Insert Function dialog box has a window into which you can enter keywords and click the Go button to search for a function, a selector to limit the functions listed, and a larger window with a scroll bar listing the functions. When you click on a function name in the lower window, information about the function is displayed. In the bottom‐left corner is a link to Help on this function. 

    AutoSum (note the keyboard shortcut)…       …opens this menu: 

     

    Recently Used opens a variable menu:  

       

    The category selector will be set to the category last used.

  •   12  * 

    Financial opens a menu with so many items it needs a scroll bar:  

     

     

     

    Logical opens this menu:  

    Text opens this menu:  

    Date & Time opens this menu: 

       

  •   13  * 

     Lookup & Reference opens this menu: 

     

    Math & Trig opens this menu (note scroll bar): 

     

    And finally, More Functions accesses multiple sub‐menus, some of which have so many functions a scroll bar is required to access all of them. 

     

    You may have noticed each of the category menus has, at its bottom, Insert Function… This opens the same Insert Function dialog box which the Insert Function icon at the far left opens, but the selector will be set to the category from which you opened the dialog box. 

     

     

  •   14  * 

    1. Returning to the Excel spreadsheet, with the numbers copied from the Google sheet, select the first empty cell beneath one of the columns of numbers. 

    2. Click the AutoSum icon, and move over the SUM function: 

    (The popup =SUM(J5:J8) is part of the pop‐up image) 

    3. Click on the SUM function. 

    You will see the proposed formula and ‘marching ants’ showing the cells to be used. 

    4. Either click the ✔ between the Name Box and the Formula Bar 

    or press J to complete the formula. 5. Move to the first free cell to the right of a row of numbers and 

    use one of the AutoSum functions. 

    6. Select a column of numbers and use one of the AutoSum functions. 

    7. Select a row of numbers and use one of the AutoSum functions. 

    8. Clear the cells with the formulas, but leave the other values in place. 

    9. Select all the numbers and use the SUM function. 

    10. Use the Undo feature. 

    11. Select all the numbers plus one column to the right and use the SUM function. 

    12. Use the Undo feature. 

    13. Select all the numbers plus one column to the right and one row down and use the SUM function. 

    And, of course, you can manually type the formula and then select the cells. Whenever you are using a function when typing a formula, Excel generates a popup which will guide you through the arguments of the function. 

     

     

     

    CreatingaNamedRangeThere are times when it is more convenient to give a range of cells a specific name. It can make formulas easier to understand and it can be easier than trying to remember the addresses of the cells. 

    1. Using a web browser, do a search for list of u.s. state abbreviations. We want the page at https://en.wikipedia.org/wiki/List_of_U.S._state_abbreviations 

    2. Copy the second row (‘Name | Status | ISO … Other’) and, in a clean Microsoft Excel workbook (spreadsheet), go to cell A1 and do a paste. (If you use a ‘Paste Special‐Match Destination Formatting (M)’ it will be a lot cleaner). 

    3. Return to the web page and copy the rows beginning with Alabama and ending with Wyoming (District of 

  •   15  * 

    Columbia will be included), return to the Microsoft Excel workbook (spreadsheet), go to cell A2 and do a paste. (If you use a ‘Paste Special‐Match Destination Formatting (M)’ it will be a lot cleaner). 

    4. Keep the Name column (Column A) and either the first ANSI (Column D) or USPS (Column E) or USPS (Column F) — they each use the same abbreviation. Delete the other columns so you have two columns of data: State Names in Column A and abbreviations in Column B. 

    5. Switch to the FORMULAS ribbon. 

    6. Select cells A1:B52. 

    7. In the Defined Names group, find the Define Name icon and click on it to open the dialog box: 

    8. In the name field/window, the contents of cell A1 will appear, but this can be changed to something more memorable and useful. (Note: neither spaces nor hyphens can be used). Let’s name it something like USPSAbbrev and then click the OK button. Verify the range selected in Step #6 appears in the last field. 

    FindingaFormula1. Enter the full name of a state in a blank cell. 

    2. Move to the cell to the right of the state name you just entered. 

    3. We want to be able to look up the abbreviation for the state in the table, but don’t know which formula to use. On the FORMULAS ribbon, in the Function Library group, click on the Insert Function icon to open the Insert Function dialog box. 

    4. Since we want to be able to lookup information in a table, let’s enter lookup in table. 

    5. Click the Go button. Excel will produce a list of functions it ‘thinks’ match the words used in the search. 

    6. The first suggestion, LOOKUP, is described as being for a one‐row or one‐column range. Since the table we created has two columns, this won’t work. Let’s look at the next function. 

  •   16  * 

    7. The next function, HLOOKUP, ‘looks for a value in the top row … and returns the value in the same column’. We need to look for a value in the left column and return a value from the same row. Let’s look at the next function. 

    8. The next function, VLOOKUP, ‘looks for a value in the leftmost column … and returns a value in the same row’. That is what we want. Click the OK button to start building a formula. 

     

    UsingaNamedRangeinaFormula/theVLOOKUPfunction9. The Functions Arguments dialog box opened in the 

    previous step will take us step‐by‐step through the process of creating a formula using the function we have selected. Its name is in the upper‐left corner. 

    10. The first argument is the Lookup_value. A cell address is needed. Either enter the cell address by typing, or click on the cell with the name of the state you created in Step 1 above. 

     

    11. The next argument is the Table_array, the cells to be searched. If you remember the name of the Named Range, you can type it in. But what if you can’t remember the exact name? 

     

  •   17  * 

    12. Have you noticed what has happened to the Function ribbon when this dialog box is open? It is almost completely greyed‐out. Almost! There is one icon available. 

    13. Click on the Use in Formula icon to open a menu of Named Ranges. 

     

    14. Click on the Named Range you created. It will be inserted into the appropriate field. 

     

     

     

    15. The next argument is Col_index_num. When you click in its box… 

    … it provides a detailed description. Since ‘[t]he first column of values in the table is column 1’ and we want the information from the second column, we will enter a ‘2’. 

  •   18  * 

    16. The final argument for the VLOOKUP function is Range_lookup. Unlike the other argument names, it is not bold. This indicates it is optional. The detailed description tells us that if the table is sorted in A→Z (ascending) order we can use TRUE or omit it. Let’s omit it and click the OK button to finish. 

    Do you have something like this? 

     

    Verify the formula by typing over the name of the state you originally used with the name of another state. Did the correct abbreviation appear in the cell with the formula? 

    Once you learn a formula, you will probably prefer to simply type it directly into the cell as it is much faster. Microsoft Excel will still offer assistance as you do so. Let’s use the VLOOKUP function again to see how. 

    1. Type the name of a different state in a blank cell and then select the cell immediately to its right. 

    2. Start the formula =v 3. You will see a list of functions whose name begins 

    with ‘V’ and a description of what the function does. You can use an arrow key to scroll down through the list (which changes as you type). 

    4. You can either double‐click on the function name (which inserts the function name and the opening parenthesis) or type in the remainder of the function name and the opening parenthesis . (You cannot arrow down to a 

    function and press J.) 5. The description of the function disappears and the 

    arguments are shown. Optional arguments are shown in brackets. The argument you are supplying is in bold. 

    6. Press w to select the cell to the left. You remain in the first argument until you end it with a , (comma). 7. To supply the table_array, you can type the Named 

    Range manually (both Named Ranges and other function names will appear [because you can use functions within functions in more complicated formulas]) as you type and the same ‘rules’ apply as in Step 4 above. Alternatively, you can use the Use in Formula icon as done in the previous exercise. Again, you remain in the argument until you end it with a comma. 

    8. Enter the col_index_num: ‘2’ — sorry, no help is offered, the assumption is you are familiar with the function — and since we will omit the optional argument at the end, type a closing parenthesis: ). For a moment, both parentheses will be in bold. Microsoft Excel does this, using different colors for different sets of 

  •   19  * 

    parentheses, to aid in ensuring every opening parenthesis has a corresponding closing parenthesis. With complicated formulas, this is very helpful. 

    9. Change the name of the state to check your formula. 

    GoogleDriveSpreadsheetsLet’s do the same thing in Google Drive Spreadsheets. 

    1. Either copy the table of state names and USPS abbreviations from Excel or from the USPS web page and paste it into a Google spreadsheet. Highlight all the cells with data. 

    2. From the menu (there is nothing on the Icon Bar for this), select Data, then Named ranges… 

    3. This will open the Named Ranges box on the right side of the spreadsheet. Since you already selected the cells, the range will be included and a proposed name will be highlighted. Let’s give it a better name. 

    4. Type in a name… 

     

    5. Then click on Done. 

     

     

    6. The Named ranges box can be left open or closed by clicking on the × in the corner. (If left open, you can see range names and type them correctly.) 

     

     

     

     

  •   20  * 

    7. Using either the Icon Bar or the Menu, select More functions… to open the web page of functions we saw earlier. 

    8. In the field to the left of the Narrow by… button, enter lookup. This will limit the list of functions. 

     

     

    9. Scroll down until you find the appropriate function. (Since we already know what it is, and that it starts with ‘V’, scroll down to the bottom of the table.) 

     

     

     

    10. Remember, this listing only provides you the information about the function. You still need to type it (or copy the function name and paste it in). 

     

     

     

     

     

     

  •   21  * 

    11. Move to the cell to the right of the cell where you typed a state’s name. Begin the formula by typing =v 

     

     

     

    12. A list of possible functions appears and changes as you type. The descriptions accompanying them are very brief. 

     

     

    13. When you see the function you want, you can either double‐click on it (it will insert the function name and the opening parenthesis) or continue typing the function’s name and the opening parenthesis. 

    14. Once the opening parenthesis has been entered, a pop‐up with detailed assistance appears. The current argument is highlighted and a small right‐pointing triangle points to the argument’s description. 

    15. Press w to select the cell to the left. The assistance pop‐up will disappear, but will return as soon as you press , (comma) to move to the next argument. 

    16. The next argument is where you need to enter the Named Range. (There is no shortcut.). Once it is entered, the cells in the range will be highlighted. 

     

     

     

     

  •   22  August 2017 

    17. Type a comma to move to the next argument. 

    18. The assistance tells us to use the column from which we want the answer, with the first (leftmost) column being ‘1’. So we want to enter a ‘2’. 

    19. Since we don’t need the optional argument, we will type the closing parenthesis. Paired parentheses will be bolded. 

    20. Press J to finish the formula. 

    Is the answer correct? Change the state’s name to be sure. 

     

    Questions? Feel free to contact Ross Valentine at [email protected] or call the library at 630.232.0780