Green Bridge Excel Data Analytics Training Courseware
Green Bridge Excel Data Analytics Training Courseware
TABLE OF CONTENTS
1 MODULE 1.............................................................................................................................. 4
2 MODULE 2............................................................................................................................ 37
3 MODULE 3............................................................................................................................ 60
Page 1 of 227
DATA ANALYTICS USING EXCEL
Page 2 of 227
DATA ANALYTICS USING EXCEL
Page 3 of 227
DATA ANALYTICS USING EXCEL
1 MODULE 1
1.1 Working With Data In Lists
1.1.1 Understanding Data lists
A list is a rectangular range of cells, with data, on a worksheet. It has one or more adjacent columns
and two or more rows. The list is usually separated from other lists on the worksheet by blank rows
and columns.
A range is a group of one or more cells with data meaning that a range is a subset of a list.
That said, the words list and range will be used interchangeably in these lessons.
Important
Click within the column and not on the column header when you want to sort.
If you click on the column header (which selects the entire column) before sorting, Excel will not
know whether you want to sort the entire range or the column in isolation. For this reason, it will
present you with a dialog asking if you want to sort the entire range or table (Expand the
selection) or to simply sort the column, potentially scrambling your data (Continue with the
current selection). Because you will very rarely (and probably never) want to sort a column
within a range in isolation it is good practice to click any cell in the column, rather than the
column header, before sorting.
Page 4 of 227
DATA ANALYTICS USING EXCEL
Figure 1
Result:
Page 5 of 227
DATA ANALYTICS USING EXCEL
Figure 3
Note 2
Important
To sort in descending order, click ZA
Figure 4
Page 6 of 227
DATA ANALYTICS USING EXCEL
Figure 5
Page 7 of 227
DATA ANALYTICS USING EXCEL
Figure 7
5) Click OK.
Result. Records are sorted by First Name first and Sales second.
Page 8 of 227
DATA ANALYTICS USING EXCEL
Figure 9
Overview
You sort data to quickly organize your data and to find the data that you want. Sorting data can help
you and other people who use your spreadsheet make more effective decisions based on your data.
You can sort data by format, including cell colour and font colour, whether you have manually or
conditionally formatted the cells.
Page 9 of 227
DATA ANALYTICS USING EXCEL
Figure 10
4) Sort by First Name (or any other column), sort on Cell Colour (you can also sort on Font
Colour and Cell Icon), and select the green colour for the first level.
Figure 12
Page 10 of 227
DATA ANALYTICS USING EXCEL
5) Click 'Copy Level' two times and select the other colours.
6) Click OK
Figure 13
Result.
Page 11 of 227
DATA ANALYTICS USING EXCEL
Figure 14
Page 12 of 227
DATA ANALYTICS USING EXCEL
Figure 15
1.1.2.4.1 Method 1
1) Enter the value “Rev” into cell F1, the value 1 into cell F2 and the value 2 into cell F3.
Page 13 of 227
DATA ANALYTICS USING EXCEL
Figure 16
3) Click the lower right corner of this range, and drag it down to cell F15 using the fill handle.
Page 14 of 227
DATA ANALYTICS USING EXCEL
Figure 18
Page 15 of 227
DATA ANALYTICS USING EXCEL
Figure 19
Result. Not only the list in column F, but also the list in column A has been reversed.
Page 16 of 227
DATA ANALYTICS USING EXCEL
Figure 20
Page 17 of 227
DATA ANALYTICS USING EXCEL
Figure 22
3.
4. Click in cell C1, locate the fill handle and drag it down to cell C5.
Figure 23
Page 18 of 227
DATA ANALYTICS USING EXCEL
Figure 24
Note: random numbers change every time a cell on the sheet is calculated. If you don't want this,
simply copy the random numbers and paste them as values.
Please open “Custom Sorting.xlsx” to continue with the example that follows.
For example, to sort by days of the week or months of the year with a built-in custom list, you do the
following:
Page 19 of 227
DATA ANALYTICS USING EXCEL
1. Click inside the range or table you want to sort. For the best results, the columns should
have headings.
2. Click Data > Sort.
Figure 26
Page 20 of 227
DATA ANALYTICS USING EXCEL
Figure 28
6. In the Custom Lists box, select the list that corresponds to the contents of the delivery
column in your worksheet, and then click OK to sort the worksheet.
Page 21 of 227
DATA ANALYTICS USING EXCEL
Figure 29
1. In a column of a worksheet, type the values you want to sort by in the order you want them,
from top to bottom. For example:
Figure 30
2. Select the cells in that list column, and then click File > Options
Page 22 of 227
DATA ANALYTICS USING EXCEL
Figure 31
Page 23 of 227
DATA ANALYTICS USING EXCEL
Figure 32
Page 24 of 227
DATA ANALYTICS USING EXCEL
Figure 33
5. In the Custom Lists box, click Import. Note that the Import list from cells box is already
populated with the range $A$1:$A$3 because you already selected it. You can change the
selection by clicking the button just next to that box.
Page 25 of 227
DATA ANALYTICS USING EXCEL
Figure 34
Result:
Figure 35
Page 26 of 227
DATA ANALYTICS USING EXCEL
Tip 1
For a short list, such as high, medium, and low, it may be faster to type it directly into the List
entries box in the Custom Lists dialog box after selecting NEW LIST under the Custom lists box.
Data Entry is a mind numbing activity. One way to make the process easier is to use the Excel data
form. It’s great when the records span across many cells.
The problem with using the default data entry method is it’s easy to lose sight of your target. You
also have to navigate to the next row. A data form solves these issues.
As you can see from the screen shot above, there are three main differences with the data form.
Page 27 of 227
DATA ANALYTICS USING EXCEL
Using the form, one can enter data faster and when one tabs to the end of the form, one can hit
Enter to start another record. One can also navigate through the records using the controls on the
right side.
1. Open Inventory-1.xlsx.
2. Adjust the width in Column A to a suitable width for all columns. The form will use this width
as the default size for all form fields.
Figure 37
Page 28 of 227
DATA ANALYTICS USING EXCEL
Figure 38
Note 3
If you get an error saying too many fields in the data form you may have selected the whole
spreadsheet or more than 32 columns. If so, try again selecting only your range. If you need
more than 32 fields, you can use a 3rd party utility such as the free Enhanced Data Form from
John Walkenbach.
Restrict data to predefined items in a list. For example, you can limit the categories to the
ones in the screen shot below. Similarly, you can create a list of values from a range of cells
elsewhere in the worksheet.
Page 29 of 227
DATA ANALYTICS USING EXCEL
Figure 39
Restrict numbers outside a specified range. For example, you can specify a minimum limit
of deductions to two times the number of children in a particular cell.
Restrict dates outside a certain time frame. For example, you can specify a time frame
between today's date and 3 days from today's date.
Restrict times outside a certain time frame. For example, you can specify a time frame for
serving breakfast between the time when the restaurant opens and 5 hours after the
restaurant opens.
Limit the number of text characters. For example, you can limit the allowed text in a cell to
10 or fewer characters. Similarly, you can set the specific length for a full name field (C1) to
be the current length of a first name field (A1) and a last name field (B1), plus 10 characters.
Validate data based on formulas or values in other cells. For example, you can use data
validation to set a maximum limit for commissions and bonuses of $3,600, based on the
overall projected payroll value. If users enter more than $3,600 in the cell, they see a
validation message.
You may opt to sort your data by Employee ID and manually identify and delete the
duplicate Employee records. This is not, however, the appropriate way of doing it. In this
lesson, we shall explore 2 methods.
Method 1
Page 30 of 227
DATA ANALYTICS USING EXCEL
3. Leaving the My data has headers checkbox selected (Since our data already has the field
labels), uncheck all columns by clicking Unselect All
4. Now select EmployeeID since it is our unique record identifier in this case.
Page 31 of 227
DATA ANALYTICS USING EXCEL
5. Click OK.
You may have noticed that Excel did not provide you with an opportunity to explore and
verify the duplicate records.
Method 2
Page 32 of 227
DATA ANALYTICS USING EXCEL
You will notice that the duplicate records are now highlighted.
You can now filter by cell colour and delete the duplicate records as you deem fit. We shall
explore filtering in another lesson ahead.
Page 33 of 227
DATA ANALYTICS USING EXCEL
When the built-in rules don't do what you need, use custom criteria in data validation, to create
special rules, such as preventing duplicates, or limiting the total in a range of cells.
When you create a formatted Excel table, you can use data validation to prevent duplicates within a
column. In this example, Employee ID is entered in the first column, and each ID must be unique.
Page 34 of 227
DATA ANALYTICS USING EXCEL
11. (Optional) On the Error Alert tab, Error Message Box, add a title: Duplicate ID and error
message: "That number has already been assigned."
12. Now try entering a duplicate ID Number.
To create the data validation, follow all the steps in the example above, and use this formula, instead
of the one shown above:
=AND(ISNUMBER(A2),LEN(A2)=5,COUNTIF(EmpIDs,A2)<=1)
The COUNTIF function prevents duplicates, the ISNUMBER function prevents text entries, and the
LEN function checks the number of digits.
Prevent the entry of a value that will cause a range to exceed a set total. In this example, the total
budget cannot exceed $3500. The budget amounts are in cells C3:C7, and the formula checks the
total in those cells
Page 35 of 227
DATA ANALYTICS USING EXCEL
The formula in this example checks that the entry in cell B2 is equal to the trimmed entry in that cell.
=B2 = TRIM(B2)
You can prevent users from adding ANY spaces in a text string. The SUBSTITUTE function replaces
each space character - " " - with an empty string - ""
The formula in this example checks that the entry in cell B3 is equal to the entry without spaces.
=B3=SUBSTITUTE(B3," ","")
Example 2
The FIND function looks for the space character - " " - and the ISERROR function result is TRUE, if the
space character is not found.
The formula in this example checks that the entry in cell B3 is equal to the entry without spaces.
=ISERROR(FIND(" ",B3))
Page 36 of 227
DATA ANALYTICS USING EXCEL
2 MODULE 2
2.1 Filtering and Querying Data
2.1.1 Apply a simple filter to a range
1. Open Inventory-1 from your sample files folder.
Notice that small drop-down arrow buttons have appeared in the range header row:
Page 37 of 227
DATA ANALYTICS USING EXCEL
Figure 42
Notice that the filter button next to Category in cell C1 has changed to show that a filter condition is
in effect.
Notice also that the row numbers along the left of the worksheet are now shaded blue and are no
longer sequential.
4. Add a second filter condition to show items in the Seafood category with an inventory value
greater than 1,000.
Page 38 of 227
DATA ANALYTICS USING EXCEL
Only rows that are in the Seafood category and exceed a value of 1,000 are now
shown.
Figure 45
Notice that the small drop-down handles have disappeared from the range header row and that all
rows are now displayed.
Page 39 of 227
DATA ANALYTICS USING EXCEL
It is possible to use this dialog to filter to a number other than ten or to filter to the
Bottom values (if you wanted to show the items with the least expensive inventory).
d. Click OK.
The ten items with the most expensive inventory are shown. Note that they are still
sorted alphabetically, in ascending order, by Product Name. You’d probably want to
sort the rows by value in descending order. Sorting will be covered later in: Sort a
range or table by rows.
The filter condition is removed and all items in the list are shown.
5. Use a custom filter to show items that have a value between 1,000 and 3,000.
Page 40 of 227
DATA ANALYTICS USING EXCEL
Filtering by colour
Excel 2007 added the ability to filter by cell colour. The Filter by Colour option only lights up when
at least one cell in the column has a background colour. You can then click the filter arrow at the
top of the column and choose Filter by Colour. This brings up a fly-out menu listing every colour in
the column:
c. Set the filter condition: is greater than or equal to 1000 And is less than or equal to
3000.
Figure 48
Only products with a value between 1,000 and 3,000 are shown.
Notice that the small drop-down arrows have disappeared from the range header row and that all
rows are now displayed.
The criteria range is the area on your worksheet where you define the advanced filter criteria.
Page 41 of 227
DATA ANALYTICS USING EXCEL
Figure 49
Each of the rows 2-4 can now be used to define the criteria needed for each column in the range.
3. Add filter criteria to show all products in the Condiments, Seafood and Confections
categories.
This is an example of a filter with three OR criteria. The filter can be defined as:
The previous lesson demonstrated that a simple filter can only include two OR criteria. An advanced
filter can contain any number of OR criteria.
Add the three filter criteria by typing (or copying and pasting) the three category names into cells
C2:C4.
Figure 50
Page 42 of 227
DATA ANALYTICS USING EXCEL
The Advanced Filter dialog is displayed with the range already defined. Because you clicked within
the range in step one, you have saved yourself the trouble of manually selecting the range.
Figure 51
The range is now filtered to display only Condiments, Seafood and Confections.
Page 43 of 227
DATA ANALYTICS USING EXCEL
Figure 53
The criteria can appear anywhere on the worksheet and does not have to be complete. It is quick
and convenient to place the criteria above the range to be filtered. You may, however, place the
criteria anywhere in the workbook – even on a different worksheet.
In this example, all of the fields in the range are listed by making a complete duplicate of the
range headers. The advanced filter will work just as well if the header list is not complete.
Example:
To filter down to the Seafood category you could simply type Category into cell J1 and Seafood into
cell J2 and then set the criteria to J1:J2.
Page 44 of 227
DATA ANALYTICS USING EXCEL
Note 6
The criteria range can span any number of rows greater than 2. In this example a criteria range of
four rows is used (A1:F4). You can use as many rows as you need in your criteria range. It is
crucial that you leave at least one blank row between the criteria range and any other range on
the worksheet.
Note 7
Note 8
This time we are going to create a criteria with both AND and OR criteria. This is another example of
criteria that is beyond the scope of a simple filter. Here are the criteria we are going to apply:
WHERE
OR
OR
Page 45 of 227
DATA ANALYTICS USING EXCEL
This will list everything in the Condiments category. It will also list products in the Seafood category
but only if their value is greater than 2,000. It will also list all products that have a value greater than
3,000 irrespective of what category they are in.
b. Apply the advanced filter using the skills learned in a previous Lesson : Apply an
advanced filter with multiple OR criteria.
c. You will see the following values in the Advanced Filter dialog:
Figure 55
You may wonder why the Criteria range displays as Inventory!Criteria this time instead of
Inventory!$A$1:$F$4. The reason is that Excel has created something called a Range Name behind
the scenes. You’ll learn all about Range Names later, in: the lesson: Using Names and the Formula
Auditing Tools.
Page 46 of 227
DATA ANALYTICS USING EXCEL
Page 47 of 227
DATA ANALYTICS USING EXCEL
(writing materials). The spell checker won’t help you find the errors because both are real words.
You can use the “Unique records only” feature to extract all unique values from the list. You can
then A-Z sort the extracted unique list to see if any words appear that have two different
spellings.
1. Open Inventory-1 if it isn’t already open.
2. Click: Data…Sort & Filter…Clear to show all items in the range.
In the Inventory workbook you will notice that one supplier often provides multiple products. For
example Speciality Biscuits, Ltd. supplies more than one product:
Figure 57
In this lesson we’ll extract a list of categories from the workbook using an advanced filter. The
advanced filter’s Unique records only feature will be used to ensure that each category is only listed
once. You will be amazed at how often you’ll find this feature useful in your day-to-day business use
of Excel.
4. Set the List range to all cells in column C within the range.
a. Click in the List range text box.
b. Click into cell C1.
c. Press: <Ctrl>+<Shift>+<Down Arrow>
Page 48 of 227
DATA ANALYTICS USING EXCEL
Figure 58
5. Leave the Criteria Range box blank and check the Unique records only check box.
Figure 59
Page 49 of 227
DATA ANALYTICS USING EXCEL
Figure 60
Notice that there are no duplicate entries in the list. The Unique records only feature has ensured
that each category is only listed once.
9. Delete column I.
10. Save your work as Inventory-5.
Tip 2
Page 50 of 227
DATA ANALYTICS USING EXCEL
special way. If you select the source sheet, display the Advanced Filter dialog, and then click into
a different worksheet to set the Copy to: cell reference, Excel will display the error message: “You
can only copy filtered data to the active sheet”. But Excel isn’t telling the whole truth! Excel will
happily let you set the List range and Criteria range from a different worksheet. It only has a
problem with the Copy to reference. The trick is to display the Advanced Filter dialog from the
destination (and not the source) worksheet.
Here’s how it’s done:
1. Select the destination sheet by clicking its sheet tab.
2. Click: Data…Sort&Filter…Advanced.
3. Set the List range, Criteria range and Copy to cell references.
You’ll then find that the advanced filter will happily extract the filtered cells to the destination
sheet.
Page 51 of 227
DATA ANALYTICS USING EXCEL
3. Select the Data tab on the Ribbon, then click the Group command.
4. The selected rows or columns will be grouped. In our example, columns A, B, and C are
grouped together.
Page 52 of 227
DATA ANALYTICS USING EXCEL
To ungroup data, select the grouped rows or columns, then click the Ungroup command.
2. The group will be hidden. To show a hidden group, click the Show Detail button
Page 53 of 227
DATA ANALYTICS USING EXCEL
Your data must be correctly sorted before using the Subtotal command, so you may want to
review our lesson on Sorting Data to learn more.
To create a subtotal:
In our example, we will use the Subtotal command with a T-shirt order form to determine how many
T-shirts were ordered in each size (Small, Medium, Large, and X-Large). This will create an outline for
our worksheet with a group for each T-shirt size and then count the total number of shirts in each
group.
1. First, sort your worksheet by the data you want to subtotal. In this example, we will create a
subtotal for each T-shirt size, so our worksheet has been sorted by T-shirt size from smallest
to largest.
Page 54 of 227
DATA ANALYTICS USING EXCEL
2. Select the Data tab..Outline Group then click the Subtotal command.
3. The Subtotal dialog box will appear. Click the drop-down arrow for the At each change in:
field to select the column you want to subtotal. In our example, we'll select T-Shirt Size.
4. Click the drop-down arrow for the Use function: field to select the function you want to use.
In our example, we'll select COUNT to count the number of shirts ordered in each size.
5. In the Add subtotal to: field, select the column where you want the calculated subtotal to
appear. In our example, we'll select T-Shirt Size.
6. When you're satisfied with your selections, click OK.
7. The worksheet will be outlined into groups, and the subtotal will be listed below each
group. In our example, the data is now grouped by T-shirt size, and the number of shirts
Page 55 of 227
DATA ANALYTICS USING EXCEL
When you create subtotals, your worksheet it is divided into different levels. You can switch
between these levels to quickly controlling how much information is displayed in the worksheet by
clicking the Level buttons for levels 1, 2, 3 to the left of the worksheet. In our example,
we'll switch between all three levels in our outline. While this example contains only three levels,
Excel can accommodate up to eight.
1. Click the lowest level to display the least detail. In our example, we'll select level 1, which
contains only the grand count, or total number of T-shirts ordered.
Page 56 of 227
DATA ANALYTICS USING EXCEL
2. Click the next level to expand the detail. In our example, we'll select level 2, which contains
each subtotal row but hides all other data from the worksheet.
3. Click the highest level to view and expand all of your worksheet data. In our example, we'll
select level 3.
Page 57 of 227
DATA ANALYTICS USING EXCEL
You can also use the Show and Hide Detail buttons to show and hide the groups within the
outline.
To remove subtotals:
Sometimes you may not want to keep subtotals in your worksheet, especially if you want to
reorganize data in different ways. If you no longer want to use subtotalling, you'll need remove it
from your worksheet.
Page 58 of 227
DATA ANALYTICS USING EXCEL
3. All worksheet data will be ungrouped, and the subtotals will be removed.
To remove all groups without deleting the subtotals, click the Ungroup command drop-
down arrow, then choose Clear Outline.
Exercise
1. Open an existing Excel workbook. If you want, you can use our practice workbook- Outlines-
Groups-Subs.xlsx.
2. Try grouping a range of rows or columns together. If you are using the example, group
columns D and E.
3. Use the Show and Hide Detail buttons to hide and unhide the group.
4. Try ungrouping the group. If you are using the example, ungroup columns D and E.
5. Outline your worksheet using the Subtotal command. If you are using the example, outline
by T-shirt size.
6. Remove subtotalling from your worksheet.
Page 59 of 227
DATA ANALYTICS USING EXCEL
3 MODULE 3
3.1 Excel Tables
This lesson introduces tables, the most important new feature in Excel 2007. Tables provide a
completely new way to work with tabular data and are particularly powerful when dealing with
dynamic data. A table is very similar to a range but incorporates several very useful extra features.
You can freely convert a table to a range, or a range to a table. The key difference between ranges
and tables is that table references shrink and grow dynamically. Here are some examples:
If you create a chart from a table and then add more rows to the table, the source data will
automatically adjust to include the new rows. This doesn’t happen with a range.
If you insert a row into a table and conditional formatting has been applied to a column, the
conditional format is automatically applied to the inserted row. This doesn’t happen with a
range.
Note 10
You can also convert a range into a table using the keyboard shortcut: <Ctrl>+<T>
Page 60 of 227
DATA ANALYTICS USING EXCEL
3. Scroll down the table and note the “sticky” column headers.
a) Click inside the table
b) Scroll down the table until the headers disappear from the top row.
In a range you would have to freeze panes in order to continue to view the range
headers. Tables are much easier to work with. The table headers are always visible
as they replace the column letters when scrolled off the screen:
Page 61 of 227
DATA ANALYTICS USING EXCEL
The function_num argument causes massive confusion as it has been implemented in a very
quirky way! The function_num can be a value of 1 to 11, each corresponding to a different
function.
For example function_num 9 is the SUM function. The function_num can also be the same
numbers with 100 added to them (ie 101-111) and these correspond to the same functions. For
example function_num 9 is the SUM function and so is function_num 109. So why do we have
109 and 9 both meaning the SUM function?
The reason is that a 109 SUM function ignores any rows that are hidden, while a 9 SUM function
will include any hidden rows. You need to know this because the total row ignores any rows
hidden by default meaning that (in this lesson’s example) the function used to total (or sum) the
column is: =SUBTOTAL(109,[Value]) This will ignore all hidden rows and, most of the time, that is
what you want. If you wanted to include any hidden rows in the total you would have to change
the formula to: =SUBTOTAL(9,[Value])
5. Change the total from SUM to AVERAGE and add a total for the In Stock column.
a) Click cell G71 (the cell containing the total).
A drop-down arrow appears next to the total.
b) Click the drop-down arrow and choose Average from the function list.
c) Click on cell F71 at the bottom of the In Stock column (the cell in the dark blue total
row).
A drop-down arrow appears next to the empty cell.
d) Click the drop-down arrow and then click Sum from the function list.
The sum of units in stock is now also displayed.
6. Change the AVERAGE in cell G71 back to a SUM.
3.1.2 Format a table using table styles and convert a table into a range
When you have formatted your data as a table, you can customize the appearance of the table using
Excel’s powerful table styles feature. You can either apply a table style from the table styles gallery
or you can create your own custom table styles. All of the pre-defined styles in the table styles
gallery follow best practice by restricting colour choice to theme colours. Themes are covered in
great depth in the Essential Skills Module in these series.
In this lesson we’ll explore the simpler of the two options by applying some of the standard pre-
defined table styles. Later (in Lesson: Create a custom table style), we’ll create a hand-designed table
style.
1) Open Inventory-6 from your sample files folder (if it isn’t already open).
2) Apply the module theme to the workbook.
a) Click: Page Layout…Themes…Themes…Module.
The module theme is applied and the colours used in the table change. The reason
Page 62 of 227
DATA ANALYTICS USING EXCEL
they change is that Microsoft used best practice when creating the built-in table
styles and restricted their colour choices to theme colours.
3) Change the theme back to the default Office theme.
4) Choose a new table style from the Table Styles Gallery.
a) Click anywhere inside the table.
b) Click: Table Tools…Design…Table Styles…More.
The More button is located on the bottom right hand corner of the Table Styles
group:
The easiest way to understand the options is to experiment by switching each option
on and off. The function of each option will then be obvious.
6) Apply the None quick table style to remove all table style formatting.
The None style is extremely useful. In a moment we’re going to convert the table back into a
range. You’ll nearly always want to remove table style formatting prior to conversion (see
note below for more on this).
a) Click anywhere inside the table.
Page 63 of 227
DATA ANALYTICS USING EXCEL
The table now looks more like a range but it is still a table and still provides all table
features.
Note 12
Page 64 of 227
DATA ANALYTICS USING EXCEL
Tip 3
Another great feature of a custom table style is that you can set it as the default for this workbook.
This saves you from continually reapplying a style every time you create a table.
1) Open Inventory-7 from your sample files folder (if it isn’t already open).
Notice that this range, (created from a table with a total row in the Lesson: Format a table
using table styles and convert a table into a range), has totals in row 71.
2) Convert the range into a table.
This was covered in the Lesson: Convert a range into a table and add a total row.
3) Convert the range total row to a table total row.
If you click Table Tools…Design you will see that the Total Row check box is unchecked.
Why then does the table appear to have a total row in row 71?
The reason is that row 71 is the total row defined in the range and has nothing to do with
the total row that is available as a table feature.
a) Check: Table Tools…Design…Table Style Options…Total Row.
A second total row appears beneath the first. This is the table total row:
Page 65 of 227
DATA ANALYTICS USING EXCEL
Page 66 of 227
DATA ANALYTICS USING EXCEL
Each of the table’s elements are listed on the left of the dialog. Each element that
had been formatted (in the style you chose to duplicate) is shown in bold face type.
e) Choose a table element and then click the Format button to set the Font, Border and
Fill formatting. To follow best practice you should restrict your colour and font
choices to theme colours and theme fonts (see note below).
f) Customize as many other elements as you wish.
g) Click the OK button.
Note 13
Example
John creates a worksheet using the default Office theme. Mary wants to use this in her
PowerPoint presentation that uses the Opulent theme. John emails the worksheet to her and then
she simply pastes the required cells into her presentation and changes the theme to Opulent. Joe
sees the presentation and wants to use the same worksheet in his Word report that uses the
Verve theme. Mary e-mails the presentation to him and then he simply pastes the required slides
DATA ANALYTICS USING EXCEL
Page 67 of 227
DATA ANALYTICS USING EXCEL
into his Word document and changes the theme to Verve. The same worksheet has been used
without modification and it blends perfectly into both Joe and Mary’s work because John
followed best practice and restricted his colour choices to theme colours.
5) Apply your new custom style to the table.
a) Click: Table Tools…Design…Table Styles…More.
b) Notice the new Custom section at the top of the gallery containing your new style.
c) Hover the mouse cursor over your new style and the style name will appear.
d) Click the style to apply it to the worksheet.
e) Change the style back to None.
6) Save your work as Inventory-8.
Important
Because structured table references are a brand new feature for Excel 2007 this feature will not
work if you have saved a workbook in Excel 97-2003 Workbook format to maintain compatibility
with earlier versions.
If this feature doesn’t work for you, even after saving your workbook in Excel 2007+ format,
somebody may have switched it off. Excel allows structured references to be switched off. You
really wouldn’t ever want to do this, as structured references are one of the most useful features of
tables. If you simply want to maintain compatibility with Excel 2003 you can save the workbook in
Excel 97/2003 Workbook format. The structured reference feature will then be automatically
disabled. You can check that this feature is enabled by clicking: Office Button…Excel
Options…Formulas…Use table names in Formulas. When the check box is checked, the feature is
switched on (the default).
One of the key differences between a range and a table is that tables shrink and grow dynamically.
The table’s ability to shrink and grow wouldn’t be useful without a way to enter a cell reference into
a formula that points to all of the rows in a table column (no matter how many rows the table
contains).
=SUM(D4:D6)
A recurring problem with data ranges is that when you add a new row to the range for April’s sales
the SUM formula has to be adjusted (to D4:D7).
Page 68 of 227
DATA ANALYTICS USING EXCEL
In order to exploit the power of dynamic tables, Microsoft had to figure out a whole new way of
referencing cell ranges. They needed a cell reference that would mean:
Because there may be several tables on a single worksheet, the cell reference needs to indicate
which table the range is in. This has been solved by adding the ability to name tables. If the table in
this example was called Sales and the column was called Amount, the formula would be:
=SUM(Sales[Amount])
This type of reference is called a structured reference. In this lesson, we’ll use Excel 2007’s brand
new structured references to create some formulas that will always give the correct result, no
matter how many rows you add or remove from a table.
Tip 4
Don’t abbreviate your table names. It may seem like a good idea to abbreviate your table names.
For example, why not call the table SL instead of Sales? On a simple worksheet such as this one
you would always know which table SL was pointing to. Imagine a workbook with a hundred
Page 69 of 227
DATA ANALYTICS USING EXCEL
tables. Your abbreviations would make the structured references very difficult to understand.
There’s no good argument for ever abbreviating table names.
4) Add a SUM function to cell G3 using a structured reference.
a) Click in cell G3 and type: =SUM(
b) Hover the mouse over the top of cell D3 until you see a black down-arrow.
c) When you see the arrow, click once to select cells D4:D7 (all of the data cells in the
column).
Page 70 of 227
DATA ANALYTICS USING EXCEL
automatically. The structured reference means: The sum of all values in the Total
column in the Sales table.
5) Add another row to the Sales table by entering 24400 in cell B7:
Note that the total in cell G3 has updated to include April’s sales figure. You can now
appreciate the power of structured table references.
Tip 5
If the table doesn’t automatically expand, somebody has switched the feature off. If this is the
case, switch it back on again by clicking: Office Button…Excel Options…Proofing…AutoCorrect
Options…AutoFormat As You Type…Include new rows and columns in table.
6) Save your work as Sales Summary-2.
Note 15
Important
Unlike ranges, an Excel table will assume that calculated fields remain consistent throughout a
column.
When you entered a formula in cell B7, Excel automatically added formulas to C7 and D7. This
saves a lot of time compared to ranges (where you have to manually AutoFill your formulas to
the remainder of the column).
3.1.5 Create a manual structured table reference
In the last lesson you created a structured reference automatically by selecting cells in a table with
the mouse.
In this lesson you’ll appreciate the powerful new tools built into Excel that make the creation of
manual structured references very easy and intuitive.
Page 71 of 227
DATA ANALYTICS USING EXCEL
1) Open Sales Summary-2 from your sample files folder (if it isn’t already open).
2) Add a formula to cell G4 that will calculate average sales using a manual structured
reference.
a) Type the words Average Sales into cell F4.
b) Press the <Tab> key to move to cell G4.
c) Type: =AVERAGE(Sa
Notice that a small icon of a table has appeared with the name Sales. If there were
more than one table on any worksheet in this workbook that began with Sa you’d
see them all listed here. It doesn’t matter whether you type Sa or SA. Table names
are not case sensitive.
d) Press the <Tab> key.
The remaining letters in the table name are entered into the formula. The table
name references all of the data in a table excluding the header and totals row. In
this case and at this time, it will reference cells A4:D7. As rows are added and
removed from the table, the cells referenced by the table name will dynamically
adjust to continue to reference all of the data in the table.
Page 72 of 227
DATA ANALYTICS USING EXCEL
f) Use the <DownArrow> key to move the highlight to the Total field.
g) Press the <Tab> key.
h) Close the square bracket.
i) Close the round bracket.
The formula should now look like this:
In a similar way to the table name, the column name will reference all of the data in
the Total column excluding the header and total rows.
In this case and at this time it will reference cells D4:D7. As rows are added and
removed from the table, the cells referenced by the table name and column name
will dynamically adjust to continue to reference all of the data in the column.
j) Press the <Enter> key to view the result of the formula.
Average sales during the period Jan-Apr were 22,778.34.
Page 73 of 227
DATA ANALYTICS USING EXCEL
Note 16
Automatic name
changing in formulas
If you change a table name or a column name, any formulas that reference the table will
automatically change. Unfortunately, this will not be the case if you have macros that reference
table names (macros will be covered later in the lesson: Forms and Macros). For this reason it is a
good idea to name your tables as soon as they are created and to avoid changing table and
column names.
These are called special items. They can be used to reference different parts of a table. The #Data
special item is rarely used because it is the default and doesn’t have to be explicitly stated. In the last
lesson you created the structured reference:
You could have entered the same formula in a different (and needlessly complex) way by adding the
#Data special item like this:
The #Data special item simply means: All of the data excluding the header and totals row.
1) Open Sales Summary-3 from your sample files folder (if it isn’t already open).
2) Add a total row to the table.
This was covered in the lesson: Convert a range into a table and add a total row.
3) Change the total at the bottom of column D so that it displays the maximum sales in any one
month (using the Max option).
a) Click in cell D8
b) Click the drop-down arrow next to the cell and select Max from the shortcut menu.
Page 74 of 227
DATA ANALYTICS USING EXCEL
This time we’re going to reference the value in cell D8 using the special item: #Totals.
5) Add an automatic structured reference to cell G5 that will reference cell D8.
a) Click in cell G5.
b) Press the equals key (=) to start the formula.
c) Click in cell D8.
An automatic structured reference is created that uses the special item #Totals to
point to the Total row.
This means: Reference the value in the Totals row of this table that is at the bottom
of the Total column.
d) Press the <Enter> key to save the formula to the cell.
The Max Sales figure is displayed.
6) Apply the comma style to cells G3:G5.
a) Select G3:G5.
Page 75 of 227
DATA ANALYTICS USING EXCEL
An unqualified structured reference may be used in formulas within the table itself. In this case you
do not have to use the table name as well as the field name because it is obvious or implied.
For example, if you wanted to add Net sales and Tax, you could use the qualified structured
reference:
It would, however, be easier and more readable to use the unqualified structured reference:
This reference works because the @ special item is the default when entering structured references
into tables.
DATA ANALYTICS USING EXCEL
Page 76 of 227
DATA ANALYTICS USING EXCEL
The @ special item is useful when you want to place a formula alongside a table and then want to
AutoFill the formula to reference each row in the table.
1) Open Sales Summary-4 from your sample files folder (if it isn’t already open).
2) Convert the A1 style references within the table to unqualified structured references.
a) Double-click in cell C4 and note the existing A1 style reference:
The formula is calculating sales tax as 15% of the net sales value.
b) Delete this formula and replace it with the unqualified structured reference:
=[Net]*0.15
c) Press the <Enter> key.
d) Double-click in cell D4 and note the existing A1 style reference:
Page 77 of 227
DATA ANALYTICS USING EXCEL
Tip 6
You can also convert a table to a range by right-clicking anywhere in the table and then clicking:
Table…Convert To Range... from the shortcut menu. The shortcut menu method is much faster
than using the Ribbon.
3.1.8 Exercise
1) Open Land Speed Records from your sample files folder.
2) Convert the range A1:F13 into a table.
3) Name the table SpeedRecord.
4) Use a simple filter to only show speed records achieved at Bonneville Salt Flats.
5) Remove the filter to show all speed records.
6) Use an advanced filter to show speed records:
a) At Bonneville Salt Flats that are greater than 575 mph.
b) Together with all records held by Tom Green (irrespective of location and top
speed).
Another way of expressing this is:
Where location = Bonneville Salt Flats AND MPH > 575
OR where Driver = Tom Green.
Here’s the result set you should see:
7) Remove the advanced filter to show all records and remove any rows that you may have
added for the advanced filter criteria.
8) Sort the table A-Z, first by Location and then by Driver.
9) Add a total row to the table and use the MAX function to display the maximum value in
column F.
10) Type Km/h into cell G1.
Page 78 of 227
DATA ANALYTICS USING EXCEL
11) Use a formula containing a structured reference to show speeds in kilometers per hour in
column G.
This is the result you should see:
Page 79 of 227
DATA ANALYTICS USING EXCEL
Operator Description
Parenthesis Any expression in brackets is always evaluated first.
(brackets) (6+2)*3=24
Exponent Exponents are always evaluated next. Exponents tend to be
used in engineering/scientific scenarios and are rarely seen in
accounting scenarios. (1+1)*6^2=72
Multiply and Divide Evaluated from left to right. When a formula only consists of
multiplication and division operators you do not have to
consider precedence:
6*2/3*3/5=2.4 3/5*2/3*6=2.4 2/3*6*3/5=2.4
Add and Subtract Evaluated from left to right. When a formula only consists of
addition and subtraction operators you do not have to
consider precedence:
6+2-3=5 2-3+6=5 -3+2+6=5
If you only ever work with accounting scenarios, all you really need to remember is:
Page 80 of 227
DATA ANALYTICS USING EXCEL
1) Open Payroll-1 from your sample files folder. This worksheet contains some simple formulas
required to compute Net Pay from Hours Worked (see image below).
Most tax regimes have more complicated rules than those defined in this simple example.
Employees are paid the same hourly rate for all hours worked. A different percentage of
gross pay is then deducted for Tax, Social Security and Pension contributions.
2) Evaluate the formula in cell B17.
Cell B17 contains the simple formula:
There’s really not much that can go wrong with such a simple formula, but let’s see how it
works using Excel’s evaluation feature.
a) Click on cell B17.
b) Click Formulas…Formula Auditing…Evaluate Formula.
The Evaluate Formula dialog appears.
Page 81 of 227
DATA ANALYTICS USING EXCEL
You can see that the first part of the formula that will be evaluated is B15. This is
indicated by an underline:
c) Click the Step In button. This will show the formula behind cell B15.
Page 82 of 227
DATA ANALYTICS USING EXCEL
e) Click the Evaluate button. The value in cell B4 now replaces the cell reference:
Page 83 of 227
DATA ANALYTICS USING EXCEL
f) Click the Evaluate button again. You can now see the result of the evaluation:
The Evaluate button has now changed its caption to Restart. If you wanted, you
could click this button to start the evaluation process all over again.
g) Click the Close button.
3) Evaluate the formula in cell B23.
To better illustrate the Evaluate feature, a formula that uses a rather long winded way of
calculating Net Pay has been inserted into cell B23:
Because of the rules of precedence, the formula works correctly. It could also have been
written with parentheses like this:
The parentheses are not needed because the precedence rules state that multiplication
happens before subtraction. I still prefer the formula with redundant parentheses (see tip
below).
Tip 7
1) Open The World’s Tallest Buildings-1 from your sample files folder.
This worksheet contains information about the world’s 20 tallest buildings. We’ll use the
SUM, MAX, MIN, AVERAGE and COUNT functions to populate cells B25:B29.
Page 84 of 227
DATA ANALYTICS USING EXCEL
A list drops down showing every function in the Excel function library beginning with S. This
is a great new feature that started with Excel 2007 that Microsoft calls Formula
AutoComplete. (If this didn’t work for you, see note below).
Note 18
Page 85 of 227
DATA ANALYTICS USING EXCEL
Notice that a little box has appeared beneath the function call. This is the Syntax box (see
note below for more information).
Note 19
6) Select the cells that you need to sum (cells F4:F23) with the mouse or keyboard. You can
select the cells with the keyboard using the following technique:
a) Press the <Up Arrow> and <Right Arrow> keys until you reach cell F4.
b) Press <Ctrl>+<Shift>+<Down Arrow> to select cells F4:F23.
7) Press the <Enter> key to finish the formula.
There’s no need to type the closing bracket as Excel is clever enough to enter it for you. The
total number of floors in all 20 buildings is now displayed in cell B25.
8) Use the same technique to add a MAX function to cell B26.
a) Click in cell B26.
b) Type = MA
c) Press the <Down Arrow> key once to move the cursor over the MAX function.
d) Press the <Tab> key to automatically enter the MAX function into cell B26.
e) Select the range D4:D23 using either the mouse or the keyboard.
The formula should now be: =MAX(D4:D23
f) Press the <Enter> key.
There’s no need to type the closing bracket as, once again, Excel helps you out by
entering it automatically.
9) Use the same technique to add MIN, AVERAGE and COUNT functions to cells B27:B29.
1) Open Mortgage Repayments-1 from your sample files folder. This worksheet contains
details of mortgages for loans from 50,000 to 300,000 with a 25 year term and an interest
Page 86 of 227
DATA ANALYTICS USING EXCEL
rate of 6.7%. We will use the PMT function to calculate the monthly repayments.
2) Calculate the monthly repayments using the PMT function and the formula palette.
a) Click in cell D4.
b) Click the Insert Function button at the left of the formula bar:
A list of functions is shown in the Select a function list. Excel’s best guess is the PMT
function. Look at the help text below the list. You can see what the PMT function is
used for:
While the help lets you know what the function does, it is unclear (at this stage)
what the arguments mean.
Note also that there is a hyperlink pointing to the help page for this function.
The help page provides detailed information about each argument. It is, however,
more convenient to obtain interactive help as each argument is entered.
d) Click the OK button.
The Function Arguments dialog is displayed.
The arguments shown in bold face are required (Rate, Nper and Pv). The last two
arguments are optional (Fv and Type). We won’t be using the Fv and Type
Page 87 of 227
DATA ANALYTICS USING EXCEL
arguments, but if you are interested in their purpose see the note below for more
information.
Note 20
f) Click in cell C4 and then type /12. We divide the annual interest rate by twelve to
calculate the monthly interest rate.
g) Complete the next two arguments by studying the help text for each. Your dialog
should now look like this:
Page 88 of 227
DATA ANALYTICS USING EXCEL
i) Click on cell D4 and add a minus operator to the front of the formula:
k) AutoFill the formula to the end of the list to show monthly repayments for all six
loan amounts.
3) Save your work as Mortgage Repayments-2.
I have loaned my friend John $20,000 to buy a car. John has agreed to repay $1,000 per month for
two years (making me $4,000 in interest on the deal). I want to sell the loan on to my other friend
Bill. Bill says he is happy to buy it from me but he needs a return of 12% on his investment. I can use
the PV function to work out what the loan is worth today based upon Bill’s requirement for a 12%
return.
I save $100 each month towards my retirement fund. If I save for 25 years and the interest rate
during this time will be 4%, how much money will I have in my fund upon retirement?
Page 89 of 227
DATA ANALYTICS USING EXCEL
In the last lesson, you discovered how to use the Insert Function button to access
functions in Excel’s vast function library.
You can also access the library by using the Function Library buttons on the Ribbon.
a) Click in cell B7.
b) Click: Formulas…Function Library…Financial…FV.
Notice the tip showing a short description of the function:
Page 90 of 227
DATA ANALYTICS USING EXCEL
d) Add a minus sign in front of PV in the formula bar to convert it to a positive value:
e) The result is $21,243.39 so you turned a profit on the deal! (The Fv and Type
arguments are discussed in the Lesson: Use the formula palette and the PMT
function.
4) Save your work as Investments-2.
Page 91 of 227
DATA ANALYTICS USING EXCEL
The IF function requires a logical test and then performs one action if the test returns TRUE and a
different action if the test returns FALSE.
Logical tests will be constructed to calculate Standard Pay, Overtime Pay and Bonus:
If you do not completely understand why the above formulas are used, read the
introduction to this lesson again.
d) Click the OK button.
Standard Pay is correctly displayed in cell F9 (525.00).
Page 92 of 227
DATA ANALYTICS USING EXCEL
Tip 8
Page 93 of 227
DATA ANALYTICS USING EXCEL
Tip 9
3.2.6 Use the SUMIF and COUNTIF logic functions to create conditional totals
In the previous lesson, you used the IF conditional function to return different values based upon a
logical test that returned TRUE or FALSE.
SUMIF and COUNTIF are similar functions but are used to sum or count values within a range based
upon a similar logical test.
This session’s sample workbook lists all of an organization’s employees along with their gender and
department:
We’ll use the SUMIF and COUNTIF functions to list the total salary and headcount for each
department, along with the total salary and headcount for each gender.
Page 94 of 227
DATA ANALYTICS USING EXCEL
The Sum-range argument is the range containing numerical data that needs to be
added up when the criteria is true. In this case, it is the range C4:C17.
c) Complete the dialog with the following arguments:
Note the use of absolute references for each range. This will allow you to AutoFill
the function for the Purchasing and Logistics totals. See note below for more on
Absolute references.
Note 21
And:
Page 95 of 227
DATA ANALYTICS USING EXCEL
Note 22
Sometimes you will only have a partial idea of what you need to find. In this case, you can use the
wildcard characters – the asterisk (*) and the question mark (?).
In the above examples, you can see that the first search finds all words that begin with C and end
with g.
The second example only finds three letter words that begin with S and end with d.
Later in this session, in: Lesson: Concatenate strings using the concatenation operator (&), you’ll
learn about concatenating strings. After this lesson, you will understand the following examples:
22 Cherry Walk
144 Cherry Road
Page 96 of 227
DATA ANALYTICS USING EXCEL
... and you want to construct a COUNTIF or SUMIF based upon the partial string contained in cell
A1 (for this example, let’s imagine that the word Cherry is in cell A1).
This would find all four values. To find values that begin with the word Cherry, you would use the
criteria:
A1 & “*”
It is possible to format a date to show only the date, only the time, or both a time and a date.
When you enter a pure time into a cell, the time is stored as a number less than one. Excel regards
this as having the non-existent date of 00 January 1900!
When you enter a pure date into a cell, the time is stored as midnight at the beginning of that day.
1) Create a new blank workbook and put the numbers 1 to 5 in cells A1-A5.
Page 97 of 227
DATA ANALYTICS USING EXCEL
2) Type the formula =A1 into cell B1 followed by the <Enter> key, and then AutoFill the formula
to the end of the list.
3) Apply a date format to column A that will show a four digit year.
This reveals that the numbers 1 to 5 represent the dates 1-Jan-1900 to 05-Jan-1900.
4) Set a custom format of dd/mm/yyyy hh:mm for the dates in column A (to show both dates
and times).
Notice that when you enter a date without a time, the time is set to midnight at the
beginning of that day.
6) Compute the number of days that occurred between 01/01/1900 and 01/01/2000.
Now that you have a good grasp of Excel’s serial numbers, this task is easy.
a) Enter the two dates in cells A7 and A8, one beneath the other.
b) Apply the comma style to cell A9.
c) Subtract one date from the other by entering the formula: =A8- A7 into cell A9.
Page 98 of 227
DATA ANALYTICS USING EXCEL
You now know that 36,525 days occurred during the last millennium (actually 36,524
due to the Lotus 1-2-3 bug – see note below).
Note 23
The peculiar case of the Excel date bug and Lotus 1-2-3
Here’s the Gregorian leap year rule © 1582 Pope Gregory XIII:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible
by 100; the centurial years that are exactly divisible by 400 are still leap years. This means that
the year 1900 wasn’t a leap year but 2000 was (causing many millennium software bugs).
The designers of Lotus 1-2-3, weren’t paying enough attention to the rules and didn’t understand
the centurial years rule. Their DATE function thus recognised the mythical date February 29th
1900.
Because Excel wanted to be compatible with Lotus 1-2-3 they had to replicate the Lotus bug when
they designed Excel.
Try entering 29th Feb 1900 into a worksheet and it will gladly accept it.
This bug has the effect of introducing a one-day error into any date arithmetic you may do that
includes a date before 29th February 1900.
Note 24
There’s a fundamental difference between Excel for the Apple Macintosh and Excel for Windows
that can cause problems.
Apple serial numbers begin on January 2nd 1904 (serial number 1) while Windows serial numbers
begin on January 1st 1900.
This can offset all of the dates when you import a Macintosh worksheet.
Page 99 of 227
DATA ANALYTICS USING EXCEL
2) Use the YEAR function to calculate the year in which each employee was born.
a) Click in cell D4.
b) Click Formulas…Date & Time…Year.
The Function Arguments dialog is displayed.
3) Use the DAY function to place the day upon which Brad Cruise was born into cell E4.
4) Use the MONTH function to calculate the month upon which Brad Cruise was born into cell
F4.
5) Use the TODAY function to place a volatile current date into cell G4.
The TODAY function returns the current date. The date is volatile; this means that if you
were to open this worksheet again tomorrow, you would see tomorrow’s date in cell G4.
Tip 10
The TODAY function is very useful, but it inserts a volatile date. In other words, the date will
change each day to reflect the current date.
You’ll often want to place the current date into a worksheet in a non-volatile way. For example,
where you want to include a Date Created cell at the top of the worksheet but you never want
this date to change.
The easiest way to do this is to use the <Ctrl>+<;> (Control plus semicolon) shortcut key.
6) Use the YEAR function to place the current year into cell H4.
By using the value in cell G4 as the argument for the YEAR function, it is possible to insert
the current year into cell H4.
Because the value in cell G4 is volatile, the value in H4 is also volatile. This means that if you
were to open this worksheet again in the year 2015, you would see the value 2015 in cell H4.
7) Add a formula to cell I4 to calculate the employee’s maximum age this year.
Calculating the employee’s current age from date of birth using the YEAR, MONTH and DAY
functions is quite a feat (although it can be done). We’ll discover an easy way to do this in
the next lesson using a different technique.
In this lesson, we’ll simply calculate what the employee’s maximum age will be this year with
a simple subtraction of the current year from the year born.
Note 25
Calculating max age this year from date of birth with a single function call
The example in this lesson is deliberately laborious as the goal is to introduce each of the
common date functions one at a time.
In a real world worksheet, you could alternatively calculate age from date of birth with a single
function call like this:
Microsoft documented the function in Excel 2000 so, in their spirit of backward compatibility, they
continue to support it in Excel 2007 and can be expected to also support it in all future Excel
versions.
DATEDIF is able to calculate the difference between two dates for several intervals. In this lesson,
we’ll use it to calculate an age from a date of birth. This is hugely complex without the DATEDIF
function (see note below).
Note 26
I’ve seen some weird and wonderful attempts to calculate age from date of birth in my student’s
worksheets.
At first, it doesn’t seem such a big deal. The first solution that occurs is to simply convert each
date to days and then divide by 365. Like this:
(TODAY() – BirthDate)/365
If it wasn’t for leap years, this would work. To overcome the leap year issue, I’ve seen solutions
based upon the assumption that a year is, on average, 365.25 days long. So why won’t this work?
(TODAY() – BirthDate)/365.25
The first reason is that the date may belong to a child who has not yet lived through a
leap year.
The second reason is caused by the Gregorian leap year rule that skips a leap year in
centurial years (see: Lesson: Understand date serial numbers sidebar).
Well yes, there is, but it is hideously complicated, involves nested IF functions and doesn’t bear
thinking about!
Aren’t you pleased that you know about the secret DATEDIF function?
Because you probably don’t have a copy of Excel 2000, here is the syntax for the function:
1) Open Resources-2 from your sample files folder (if it isn’t already open).
2) Change the text in cell I3 to Age (Years).
3) Delete cells I4:I12.
3.2.10 Use date offsets to manage projects using the scheduling equation
Note 27
Project Management involves scheduling tasks and assigning resources to complete each task.
For example, to build a house you would have tasks such as lay bricks and fit windows.
Each task has a start and end date and one or more dependencies (for example you cannot fit the
windows until you have laid the bricks).
Each task also has one or more resources assigned to it (for example you may assign Bill and Bob
to lay the bricks and Colin to fit the windows).
The best way to illustrate a project plan is the Gantt chart named after Henry Gantt (1861–1919).
It is quite easy to produce a primitive Gantt chart using Excel (but not a true Gantt chart showing
inter-task dependencies).
Now that you understand Excel’s date functions, you might think that Excel is a great tool for
managing projects – but there’s a far, far better way.
Microsoft Project is a tool designed specifically to manage projects and produce excellent Gantt
charts.
If you have complex workbooks that seek to manage the type of scenario described above you
really should check out Microsoft Project – it is a superb tool.
Many students that attend my Project Management courses have first tried hard and failed using
Excel!
In this lesson, we’ll use date offsets in conjunction with the scheduling equation to create a
worksheet that will manage a small project.
In order to understand project management, you need to first understand the scheduling equation:
Time = Work/Units
“If it takes one man ten days to dig a hole how long will it take two men to dig the same hole”? The
answer is, of course, five days (in mathematics, if not in reality)! To use the scheduling equation, we
describe each unit as being a man and define the work in days.
If you increase your estimate of 10 days work, then the time will increase. If you add more men to
the task, then the time will decrease as the equation will always balance.
In this lesson, you’ll learn how to create formulas that will enable task lengths to dynamically re-
scale as you add more resources to each task, or revise your estimate for the amount of work
needed to complete each task.
Each task has a start to finish dependency. This means that each task must complete before
the following task can begin.
2. Calculate the End Date for the first task.
Enter the formula: =B4+C4/D4-1 into cell E4.
Note that, because of the rules of precedence, this is the equivalent of =B4+(C4/D4)-1.
DATA ANALYTICS USING EXCEL
(Precedence was covered in: Lesson: Understand precedence rules and use the Evaluate
feature).
We subtract one day so that a job of one day’s duration will begin and end on the same day.
The formula calculates the End Date using the scheduling equation discussed at the
beginning of this lesson.
The End Date is 15-Jun-09 because we have assigned three men to the task which has three
man-day’s work. The task thus takes one day to complete and so begins and ends on the
same day.
3. Test the scheduling equation.
If you were to take two men off the job the single remaining man would take three days to
complete the task.
a. Change the value in cell D4 to 1.
Notice that the task now takes three days to complete.
b. Revise your estimate of the work to 6 Man-Days and assign two men to the task.
This time, the task takes three days to complete.
4. Add a formula to show the start date for the Pour Footings task.
The start date of the Pour Footings task will be the day after the End Date of the Dig
Foundations task.
Enter the formula: =E4+1 into cell B5.
5. AutoFill cells B5 and E4 to the end of the range.
You now have a dynamic project plan that will adjust the end date of the project based upon
your work estimates and the number of resources that you assign to each task.
3.2.11 Use the DATE function to offset days, months and years
Now that you understand the TODAY, DAY, MONTH and YEAR functions, we can introduce the DATE
function to dynamically manage more sophisticated date offsets.
2. Put a formula in cell B4 that will calculate the date for the 20 day inspection based upon the
date in cell A4.
a. Type =D into cell B4.
The DATE function is the first in the drop-down list:
b. Press the <Tab> key to enter the formula into the cell.
c. Click the Insert Function button on the left of the formula bar:
Tip 11
Note that in the case of the Day argument, we have added the number 20 to create
a date that is 20 days later than that in cell A4.
e. Click the OK button.
A date is shown that is 20 days after 16th January 2008:
3. Put a formula in cell C4 that will calculate a date that is three months later than the 20 day
inspection date. This time your dialog should look like this:
4. Put a formula in cell D4 that will calculate a date that is twelve months later than the 3
month inspection date. This time your dialog should look like this:
In Lesson: Understand date serial numbers, we discussed how Excel combines time and date
information in a single date serial number.
Excel represents dates by counting from 1st January 1900 to the present day. For example, the date
serial number 2.0 represents midnight (00:00) on 2nd January 1900.
Excel represents time using the decimal part of the serial number. For example, the date serial
number 3.5 represents midday on 3rd January 1900.
Excel also allows you to work with pure time values (times that do not have an associated date). In
this case, the mythical date of 0 Jan 1900 is used. For example, the date serial number 0.3333
represents the time 08:00 but does not represent any date at all.
In this lesson, we’ll focus on entering time values into a worksheet without any associated date and
explain how to avoid the mistakes commonly made when working with time values.
3. Add a start time of 10:00 AM and finish time 6:00 PM for Tuesday.
AM/PM notation is preferred by some users, but is more error prone than the
recommended 24-hour notation.
Type 10:00 AM into cell B9 and 6:00 PM into cell C9. Make sure that you leave a space after
the time otherwise Excel will interpret the value as text rather than time.
Depending upon which country you are in, your dates and times may display differently to
those shown above. See note below for more information about how your regional settings
affect the default format of dates and times.
Note 28
Important
Why do my time and dates look different from the ones in the screen grabs?
The default format for times and dates are based upon the Regional Settings set up in Windows.
To view your regional settings go to the Windows Control Panel and select: Regional and
Language Options.
Here are the default English (United Kingdom) settings:
Important
This would mean that a machine that was set up with default English (United Kingdom) settings
would display:
08:00
While a machine set up with default English (United States) settings would display:
8:00
These are, of course, only the defaults and you will normally apply a specific format to times as
we do at the end of this lesson.
5. Examine the date serial numbers in cells B8:C12.
a. Select cells B8:C12.
b. Right-click the selected cells and click Format Cells… on the shortcut menu.
c. Click the General in the Category list.
d. Click the OK button.
Notice that all time values begin with zero. This is because no date is associated with
them. Understanding this is very important when creating time formulas.
Notice that the time in cell B8 is 0.333333. This is because at 08:00 33.333333% of
the day has elapsed, as eight hours is 33.333333% of 24.
Tip 12
You can also return to General format using the shortcut key:
<Ctrl>+<Shift>+<~>
6. Add a formula to cell D8 that will calculate the number of hours worked.
DATA ANALYTICS USING EXCEL
The result shows that Frank worked for 37.5% of the day on Monday.
7. Format cells B8:D12 to show times in the 24-hour format.
a. Select cells B8:D12.
b. Right-click the selected cells and click Format Cells… from the shortcut list.
c. From the Custom category set the format to hh:mm. (By typing or selecting it if it’s
available in the options)
d. Click the OK button.
The number of hours and minutes worked is now shown in cell D8.
Tip 13
In this lesson, we subtracted 08:00 from 17:00 giving a result of 0.375 representing 9 hours as
37.5% of one 24-hour day.
Sometimes, it is convenient to express times as simple decimal numbers (in this case as 9.0). In
order to convert a time serial number to a numeric value representing hours, you simply multiply
the serial number by 24:
Tip 14
You can also open the Format Cells dialog using the shortcut key:
<Ctrl>+<1>
A problem is now revealed. On Wednesday and Thursday, Frank’s working times spanned
midnight. Unfortunately, Excel doesn’t know this. A row of hashes is shown to signify an
error as Excel cannot display a time of minus 18 hours.
3. Correct the formulas in cells D8:D12 so that time is correctly calculated, even when the
times span midnight.
Fortunately, it is very easy to correct the formula using the IF logic function covered in:
Lesson: Use the IF logic function.
a. Change the formula in cell D8 to the following:
=IF(C8>B8, C8-B8, C8+1-B8)
The formula works by adding the number one (representing one day) to the finish
time when the finish time is less than the start time.
b. AutoFill the formula from cell D8 to cells D9:D12.
The times are now correctly calculated:
4. Add a formula to show the total hours worked this week in cell D13.
Add a SUM function to cell D13 to sum the values in cells D8:D12.
The formula doesn’t return an error but it seems to produce the wrong answer:
The answer is actually correct. The problem lies in the way in which cell D13 is formatted.
DATA ANALYTICS USING EXCEL
Remember that the date serial numbers in cells D8:D12 contain the percentage of each 24
hour day that was worked. When they are added together they will add up to more than
one. Because cell D13 is formatted to show times it will ignore the whole number part of the
date/time serial number, believing that this represents a date.
The actual value in cell D13 is 1.583333 and that represents 14:00 on 1st January 1900.
5. Display the value in cell D13 correctly by adjusting the format. There are two ways to solve
this problem. We’ll solve it using a custom format. The other potential method is discussed
in the Tip below. Because adding time values is a common requirement, Excel provides a
special custom format to display times that exceed 24 hours.
a. Click on cell D13.
b. Click Home..Number..Dialog Launcher
In this lesson, we used the [h]:mm custom format to display the time data correctly.
The value 1.5833 actually means 158.33% of a 24 hour day so another method of correcting the
result would be to multiply by 24:
=SUM(D8:D12)*24
The advantage of this method is that it is often easier to work with numerical values than with
date serial numbers if you need to perform further mathematical calculations.
You’ll see this technique in action in: Lesson 3-14: Understand common time functions and
convert date serial numbers to decimal values.
Tip 16
You can also open the Format Cells dialog using the shortcut key:
<Ctrl>+<1>
3.2.14 Understand common time functions and convert date serial numbers to decimal
values
Excel’s primary time functions are NOW, HOUR, MINUTE and SECOND. In this lesson, you’ll learn
how to use all of them along with some important techniques when performing calculations with
time values.
1. Open Time Sheet-3 from your sample files folder (if it isn’t already open).
e. Use a SUM function to show total earnings for the week in cell E13.
The correct earnings figure is now shown in every case.
3. Add a NOW function to cell B15 to display the current date and time.
a. Type Current Date and Time into cell A15.
b. Click on cell B15.
c. Type =NOW
The tip advises that this function returns the current date and time. This is a little
like the TODAY function encountered in Lesson: Understand common date functions
except that it returns the date and the time rather than midnight on the current
date. The current date and time is the time that the worksheet was last recalculated
(we’ll learn how to recalculate the worksheet later in this lesson).
d. Press the <Tab> key twice.
e. If necessary, widen columns A and B so that they are wide enough to see all of their
contents.
The NOW function is very useful but it inserts a volatile date and time. This means that the date
and time will change to reflect the current date and time.
You’ll often want to place the current date and time into a worksheet in a non-volatile way. For
example, where you want to include a Date and Time Created cell at the top of the worksheet but
you never want this date and time to change.
Current Date: Use the <Ctrl>+<;> (Control plus semicolon) shortcut key.
Current Time: Use the <Ctrl>+<Shift>+<;> (Control plus Shift plus semicolon) shortcut key.
Tip 18
<F9>
If you have a very large workbook with multiple sheets and hundreds of formulas, it can take a
significant time to recalculate. In this case, you can recalculate the currently selected worksheet
by pressing:
<Shift>+<F9>
3.2.15 Use the TIME function to offset hours, minutes and seconds
In this lesson, we will use the TIME function in conjunction with the HOUR, MINUTE and SECOND
functions to offset time data.
We’ll construct a train timetable that will run a service every 10 minutes before 09:00 and every
hour thereafter.
This will work because all of the subsequent journeys will be defined as offsets from the first
2. Put a formula in cells C6:K6 that will calculate the arrival times of subsequent trains on the
Northern route. We know that trains arrive every 10 minutes before 09:00 so would expect
trains at 08:40, 08:50 and 09:00. After that, we would expect trains each hour at 10:00,
11:00, 12:00…
a. Click in cell C6.
b. Click: Formulas..Function Library..Date & Time..Time.
The Function Arguments dialog appears.
c. Enter the following values for each argument:
Unfortunately, that isn’t what we wanted. After the 09:00 train there shouldn’t be
another until 10:00. To fix the formula, we need to add an IF function that will check
the time of the previous train. If the time is later than or equal to 09:00, the
increment should be one hour and not 10 minutes. (The IF function was covered in:
Lesson: Use the IF logic function).
f. Copy the function from cell C6 excluding the = sign by clicking in cell C6, selecting
the function in the formula bar (but not the = sign) and then copying (by pressing
<Ctrl>+<C> or by right-clicking and then selecting Copy from the shortcut menu).
3.2.16 Use the AND and OR functions to construct complex Boolean criteria
When using logical functions such as IF, COUNTIF and SUMIF, you need to construct a logical test
(sometimes also called criteria) that will return TRUE or FALSE.
E9<=35
This Boolean expression returns TRUE if the value in cell E9 is less than or equal to 35, otherwise it
returns FALSE.
In this lesson, we’ll use the Logical functions AND and OR to create more complex Boolean criteria.
The sample file for this lesson computes bonuses for employees, based upon the following rules:
Here are the bonus figures for the first three employees:
You can see that Johnny Caine exceeded his target but received no bonus because he only
has two years’ service.
George Marley has over five years’ service and thus receives bonus even though he didn’t
reach his sales target.
Betty Annan has three years’ service and she has also exceeded her sales target, so she
receives her bonus.
Another way of expressing the logical test that governs when bonus will be paid is:
A logical expression can be created to implement the rules using Excel’s AND and OR functions.
Here’s how we can use the AND function to test that Johnny Caine’s sales are above target AND that
he has more than two years service
=AND(C10>D10, B10>2)
The AND function will return True only if both expressions evaluate True. In Johnny’s case, it will
return False because Johnny only has two years’ service.
We also need to check whether the employee has over five years’ service. Here’s how we can use
the OR function to do this:
The OR function will return true if either of the arguments return true. In Johnny’s case, this will still
return false as he also has less than five years’ service, but in George’s case, it would return true
since George has seven years’ service.
Now that you understand how to construct the logical test for the bonus calculation, we can create
the IF function for the sample file.
1. Automatic: Whenever you change the value in a cell, all values that reference that cell are
automatically recalculated. This is the default.
2. Automatic except for data tables: This is similar to Automatic, but tables will only be
recalculated when one of the values within a table is changed.
3. Manual: Calculation will only take place when the <F9> key is pressed.
Most users are unaware that the calculation options exist and leave Excel set to the default
Automatic at all times.
So why would you ever need the other two options? The answer is that Excel worksheets can be
very big indeed (over a million rows and over 16,500 columns). A worksheet could contain many
millions (or even many billions) of formulas. Such a worksheet is very unusual, but could take a
substantial amount of time to recalculate. You wouldn’t want to have to pause for recalculation
every time you edited such a worksheet, so you would switch to one of the other two calculation
modes under those circumstances.
The dealer makes 33% Gross Profit (sometimes also called Margin, Gross Margin or Gross
Profit Margin) on all watch sales (see sidebar for a discussion of the difference between
gross profit and mark up).
The formula in column D:
=C8/(1-$D$5)
... calculates the selling price based upon the gross profit stated in cell D5.
2. Change the gross profit to 25%.
When the value in cell D5 is changed to 25%, the worksheet recalculates to show the new
selling prices.
This is exactly what you would expect because this workbook has the default automatic
calculation mode.
3. Change the calculation mode to manual.
Click: Formulas..Calculation..Calculation Options..Manual.
4. Change the gross profit to 30%.
This time nothing happens because the worksheet will only recalculate when you explicitly
request a recalculation.
Note 30
The second workbook is also in manual calculation mode because only one calculation mode can
exist for all open workbooks.
Things become even more confusing because the calculation mode is saved with the workbook.
Suppose that you had two workbooks called Manual and Automatic. The first was saved in
manual calculation mode and the second saved in automatic calculation mode.
If you open the Manual workbook followed by the Automatic workbook, then both workbooks
will be set to Manual calculation mode, as this was the mode of the first workbook opened.
If you open the Automatic workbook followed by the Manual workbook then both workbooks will
be set to Automatic calculation mode.
Abc123
John Smith
4+2=6
4 & 2 = 42
Concatenation is rarely used with numbers. It is more likely that you may wish to concatenate
Salutation, First Name and Last Name cells to produce full name. For example:
Note the use of double quotation marks to indicate that each value is a string.
In this example, it would be nice to have spaces between each of the words. To do this, we would
add a string containing only a space between each word. Here’s how it’s done:
= “Mr” & “ “ & “John” & “ “ & “Smith” = “Mr John Smith”
1. Open Classic Watches-2 from your sample files folder (if it isn’t already open).
2. Type Classified Ad into cell F7 and apply the Heading 3 style.
To apply the Heading 3 style, select cell F7 and then click:
Home..Styles..Cell Styles..Titles and Headings..Heading 3
Cell styles are covered in depth in our Essential Skills course.
Cells F8:F17 will contain text to be included in a classified ad listing in the local newspaper.
We want to show the description of the watch, the year of manufacture and the selling
price.
The Breitling Duograph is priced at $16,428.57. It would be cleaner to round all of the prices
up (or down) to the nearest five dollars. This can easily be achieved using the MROUND
(multiple round) function.
=C8/(1-$D$5)
TO
=MROUND(C8/(1-$D$5),5)
As described in the introduction to this lesson, this can easily be achieved using the
concatenation operator. The correct formula is:
The only thing we have a problem with is the comma in the cash price of the watch ($16430
should be $16,430). In the next lesson, we’ll discover how to solve this problem using the
TEXT function.
Zeroes are used in formatting codes to define the number of decimal places that are required, along
with leading and trailing zeroes. Here are some examples (reproduced from the Essential Skills
course).
The hash symbol (#) is mainly used to add comma separators to thousands and millions. Here are
some examples (once again, reproduced from the Essential Skills Course).
Because the hash symbol can be used in conjunction with zeroes, it is also possible to indicate that
you want both thousand separators and a specific number of leading or trailing zeroes.
1. Open Classic Watches-3 from your sample files folder (if it isn’t already open).
2. Delete the contents of cells F8:F17.
3. Use the CONCATENATE function to place the classified ad into cell F8 in the format: Breitling
Duograph 18K (1948) - $16,430.
The concatenation operation (&) used in the last lesson provides a quick and easy way to
concatenate text:
It would be possible to use the TEXT function in conjunction with the concatenation
operator (&) to construct the formula. This approach would result in the formula:
... which is difficult to read and prone to error. Instead, we’ll use the CONCATENATE
function.
When you add an argument to the Text2 box, a Text3 box magically appears.
The dialog then continues to expand as you add each argument until the maximum of 255 is
reached.
Note that each string is enclosed in double quotation marks to denote text.
Note also the use of the TEXT function with a reference to cell D8 followed by the
custom format string :
"$#,#0"
This format string means “show a leading dollar sign, show a comma after thousands
and show only whole numbers (no decimal places)”.
DATA ANALYTICS USING EXCEL
3.2.20 Extract text from fixed width strings using the LEFT, RIGHT and MID functions
You can split fixed width data using Excel’s Text to Columns feature. While this works well, you’ll
often need to extract data dynamically using a formula. In this lesson, we’ll use the LEFT, RIGHT and
MID functions to do just that.
This worksheet lists some of the best-selling fiction books of all time:
For this lesson, the interesting data is in column E; the International Standard Book Number
(ISBN-13).
ISBN numbers are a good example of fixed width strings. At first they simply seem to be a
jumble of numbers but they actually contain four discrete pieces of data:
2. Use a LEFT function to extract the EAN from the ISBN code.
We know that the leftmost three digits represent the EAN. The LEFT function extracts a
given number of digits from the left part of a string.
3. Use a RIGHT function to extract the Check Digit from the ISBN code.
We know that the rightmost single digit represent the Check Digit. The RIGHT function
extracts a given number of digits from the right part of a string.
4. Use a MID function to extract the Group from the ISBN code.
The MID function extracts text from within a string. We know that digit 4 is the Group
Identifier and will tell us the language that the book is written in. Because the ISBN has a
dash between the third and fourth digits, we’ll have to extract a single character from
position five in the string.
5. Use a MID function to extract the Publisher and Title code from the ISBN code.
This time, the correct arguments for the dialog will be:
You can now see from the Group (country or language code) that Le Petit Prince was
published in French and Heidis Lehr- und Wanderj was published in German.
Allow for formatting characters when using the LEFT RIGHT and MID functions
Consider a cell that contains the value 28 in cell A1 and has been formatted as currency using the
dollar currency prefix. The cell would display the value:
$28.00
But the actual value in the cell (and displayed on the formula bar) would be:
28
If you were to extract the first character using the LEFT function
=LEFT(A1, 1)
...you would extract 2 and not $ because the $ character is simply displayed as a result of the
cell’s formatting and is not part of the data in the cell.
Tip 19
In this lesson, you learned how to extract several numeric codes from an ISBN number.
Notice that the results are left formatted in each cell. This tells you that they are textual, rather
than numeric values.
To convert the textual return value of a formula to a true number, simply multiply the result of
the formula by 1.
For example, to return the EAN as a numeric value you would use the following formula:
=LEFT(E4,3)*1
It is interesting to note that there are many other mathematical operations that will achieve the
same result, such as adding 0 (+0), dividing by 1 (/1) adding two negative signs in front of the
number (--) and even raising to the power of 1 (^1).
3.2.21 Extract text from delimited strings using the FIND and LEN functions
Here are two examples of international telephone numbers.
The country code (or international dialling code) is shown as a + symbol followed by one or more
numbers. The NDD (National Direct Dialling prefix) is shown in brackets. This is the access code used
to make a call within the relevant country but is omitted when calling from outside the country. The
Area Code consists of the numbers after the closing bracket but before the hyphen.
In this lesson, we’ll use the FIND and LEN functions in combination with the MID function to extract
the country code, NDD and phone number from an international telephone number.
The FIND function demands three arguments. The first is the character to find (in
this case the opening bracket), the second is the text to search within (in this case
the telephone number in cell B4). There’s also an optional argument that allows you
to begin the search at a specified position within the string.
Note that you don’t have to manually type the quotation marks around the text in
the Find_text argument. Excel will helpfully add them for you automatically.
The number 5 is shown in cell C4. This is because the opening bracket is positioned
five characters from the left of the string +44 (. Note that the space before the
opening bracket is counted as a character.
3. Insert a FIND function into cell D4 to find the first occurrence of a closing bracket within the
telephone number.
Repeat Step 2, but use a closing bracket for the Find_text argument.
4. Insert a FIND function into cell E4 to find the first occurrence of a hyphen within the
telephone number.
Repeat Step 2, but use a hyphen (“-“) for the Find_text argument.
5. Insert a LEN function into cell F4 to find the total number of characters in the telephone
number.
a. Click in cell F4.
b. Click: Formulas..Text..Len.
c. Click Cell B4 for the single argument for this function.
d. Click the OK button.
The length of the telephone number string (18 characters) is displayed in cell F4.
Note that C4-1 is used for the number of characters to avoid returning the opening bracket.
This could result in a trailing space (see note below for a way to remove trailing spaces).
The MID function was covered in: Lesson: Extract text from fixed width strings using the
LEFT, RIGHT and MID functions.
Select columns C:F, right click the mouse and then click Hide on the shortcut menu.
The retailer has created a stock code to save time when creating invoices. The code is made up of
the first two letters of the watch description, along with the two last numbers of the date of
manufacture.
When provided with a stock code, the VLOOKUP function can scan all of the codes in column A until
a match is found and then return a value from the same row for any of the other columns.
DATA ANALYTICS USING EXCEL
In this lesson, we will create a VLOOKUP that will automatically return the Description of any watch,
into column B when the user enters a stock code into column A.
2. Convert the range A5:G15 on the Stock worksheet into a table named Stock.
This was covered in: Lesson: Convert a range into a table and add a total row and Lesson:
Name a table and create an automatic structured table reference.
When working with the VLOOKUP function in Excel 2013, it is best practice to use a table for
the Table_array argument (see note below).
Using a table will make the data dynamic. In other words, the VLOOKUP will still work
correctly if you add and remove rows from the Stock table.
3. AutoSize all columns so that each column is wide enough to display all data.
4. Insert a VLOOKUP function into cell B6 on the Invoice worksheet to find the description to
match the Code in cell A6.
a. Click in cell B6.
b. Click: Formulas..Function Library..Lookup & Reference..VLOOKUP.
The VLOOKUP Function Arguments dialog appears. It can be seen that the VLOOKUP
function has three required arguments (shown in bold face) and one optional
argument:
This is the cell on the Invoice worksheet that provides the value to be searched for in
Column A of the Stock worksheet. We want to look up the description for the watch that has
the code CA74. This is contained in cell A6.
The table array is the range, table or name (see note below) we will search for a match to
the value in cell A6. VLOOKUP always searches the left-most column of the range, table or
name.
It is best practice to use a table for the Table_array argument (see note below).
Counting from left to right, the Col_index_num argument is the column that contains the
value we want to return. In this case, it is the Description column, so we want to return
column 2.
If it is left blank, VLOOKUP will return an inexact match. Later, in Lesson: Use a VLOOKUP
function for an inexact lookup, we’ll find why that might be useful, but in this case we want
an error to be returned if the stock code is not found, so it is vital to set this argument to
FALSE.
This is best practice in Excel 2013, but it wasn’t possible in Excel 2003 as the (fantastically useful)
table feature wasn’t available.
In worksheets constructed using earlier versions of Excel it is common to see absolute range
references for Table_array arguments.
You learned how to add a VLOOKUP in Lesson: Use a VLOOKUP function for an exact lookup.
This time, the correct arguments are:
This is nearly what is needed. The invoice will work just fine when all three lines are
populated:
But we need to cater for customers that only wish to purchase one watch. To make this
work, we need to suppress the error messages when some invoice lines have no stock code.
4. Wrap each VLOOKUP function with an IFERROR function to return a blank space when an
error is encountered.
The IFERROR function can return the value of your choice whenever a formula returns an
error.
This is the VLOOKUP that returns the description. We’re going to use this formula as
the value argument for the IFERROR function. When one function is used inside
another function in this way, we sometimes refer to the outside function as a
wrapper.
b. Click just to the right of the equals sign in the formula bar.
c. Type IFERROR(
Notice the tip that has appeared. The entire VLOOKUP function is now being used as
the value argument for the IFERROR function.
d. Click to the extreme right of the formula in the formula bar and add a comma:
You are now ready to add the second argument for the IFERROR function. This
argument defines what will be displayed if the VLOOKUP function returns an error.
Type “”. This is an empty string and tells Excel to keep the cell blank when an error is
returned.
The invoice now works fine, even when some stock codes are left blank.
Tip 20
I’ve noticed in my classes that many students will respond to the instruction:
Sometimes you don’t want to search for an exact match but are interested in the nearest match.
This is called an inexact lookup. Consider the following exam grades:
If we were to perform an exact lookup on a mark of 80%, it would correctly return a grade of A. A
student with a mark of 77% would result in an error because there is no exact value of 77% in
column E.
If we ask VLOOKUP to perform an inexact lookup, it will return an exact match if one is found. If an
exact match is not found, it will return the largest value that is less than the lookup value.
For VLOOKUP to work with inexact matches, it is vital that the lookup column is sorted in ascending
order (from the lowest to the highest value).
In the above example, a search for 68% would find row 5 (a C grade) because 60% is the largest
value that is less than 68%.
This was covered in: Lesson: Convert a range into a table and add a total row and Lesson:
Name a table and create an automatic structured table reference.
When working with the VLOOKUP function in Excel 2013, it is best practice to use a table for
the Table_array argument.
This will make the data dynamic. In other words, the VLOOKUP will still work correctly if you
add and remove grades from the Grade table.
3. Add an inexact VLOOKUP to cell C4 to return the grade that corresponds to the percentage
mark in cell B4.
You learned how to add an exact VLOOKUP in Lesson: Use a VLOOKUP function for an exact
lookup. An inexact lookup is done in exactly the same way, except that the Range_lookup
argument is set to TRUE (or omitted, as the default is TRUE).
3.2.25 Exercise
1 Open Employee Summary-1 from your sample files folder.
2 Using the RIGHT, LEFT, LEN and FIND functions, split the Full Name in column A into Last Name and
First Name in columns B and C.
3 Use an exact VLOOKUP to return the Department for each employee (departments are listed on
the Departments worksheet).
4 Use a COUNTIF function to return the headcount for each department in cells B20:B22.
5 Use the YEAR function to populate column F with the year each employee started.
6 Each employee in the Sales department receives a 10% bonus while all other employees receive a
5% bonus. Use an IF function to populate column G with the correct bonus percentage.
It is amazing at how many highly experienced Excel users are unable to understand Pivot tables.
Many users spend hours creating a worksheet based solutions that could have been addressed in a
few seconds using a pivot table.
This session will empower you with a complete mastery of this essential Excel tool.
Session Objectives
This is the type of worksheet that pivot tables can work well with because the columns contain
repeating data.
The sample file contains over 2,000 rows of transactional data listing sales during the 18 month
period from October 2007 to March 2009 inclusive.
You can see from the data that the worksheet contains details of orders sold by a DVD wholesaler,
along with the titles supplied on each order.
Order 136438 was placed on 1st-Oct-07 and was ordered by Silver Screen Video. The order was sold
by Frank Lee and there were four items on the order. Two of the films ordered were in the Drama
genre and the other two were in the Biography and Comedy genres.
A business may wish to ask several questions about sales during this period such as:
In this lesson, you'll use a pivot table to answer both questions in less than 10 seconds!
6. Clear all check boxes and then select the Employee and Qty check boxes.
Once again, with very little effort, you have answered the second question:
How many units did each Employee sell?
Note 36
The report now breaks sales down by Employee, Genre and Title.
The fastest way to collapse and expand an outline is by using the right-click method described in
the text. It is also possible to do this in a less efficient way using the Ribbon:
1. Click cell A5.
A5 becomes the Active Field.
2. Click: PivotTable Tools…Options…Active Field…Collapse Entire Field
ii. Click: Expand/Collapse…Collapse Entire Field.
The Pivot Table collapses to the level of Employee.
8. Collapse the outline so that Dan’s sales by Genre are shown without Title details.
i. Right-click cell A6.
A shortcut menu appears.
ii. Click: Expand/Collapse…Collapse Entire Field.
The Title level of the Pivot Table collapses to show Dan’s sales by Genre but not by
Title.
At the moment, we have three columns in the Row Labels list and one in the Values list. This
creates a pivot table that shows sales first by Employee, then grouped by Genre and then
grouped by Title.
4. Remove the Genre and Title rows from the Row Labels list.
i. Click Genre and then click Remove Field from the shortcut menu.
ii. Click Title and then click Remove Field from the shortcut menu.
The pivot table now shows sales for each employee by genre with the genres listed along the
top row as column labels:
ii. Click the small – sign that has now appeared to the left of Action in cell B4.
The outline collapses back to the genre level:
Excel is capable of importing data from a huge range of sources such as a CSV (comma separated
value) file. Once the data is imported into an Excel worksheet, it is then possible to create a pivot
table from the worksheet.
It is also possible to use data directly (without first importing it) from an external data source. This is
usually a database such as Microsoft Access or one of its big brothers; SQL Server or Oracle.
Note 37
You can also use data directly from an OLAP cube. An Online Analytical Processing (OLAP) cube
resides on an OLAP server and is a special sort of database that is optimized for reporting speed.
OLAP technology would typically only be used when working with very large business databases.
In this lesson, we’ll create a worksheet that analyses data from an Access database.
Note 38
Important
You may not be able to complete this lesson unless you have Microsoft Access 2007 installed on
your machine. Access is included in the professional version of Office 2007 but, unfortunately, not
the standard version.
If you don’t have Access installed, you may still wish to read the lesson in order to understand how
pivot tables can be used with an Access database.
1. Open a new blank workbook.
2. Save the new workbook as Film Details-1.
3. Click Insert…Tables…PivotTable.
The Create PivotTable dialog appears.
4. Create a pivot table using the qryFilmDetails query in the Film Library Access database as an
external data source.
i. Click the Use an external data source option button.
ii. Click the Choose Connection… button.
vi. Click the qryFilmDetails query and then click the OK button.
vii. Click the OK button.
5. Use the pivot table to display all of the film titles, and each film’s budget.
Check the Film Budget (Millions $) check box and the Film Title check box in the PivotTable
DATA ANALYTICS USING EXCEL
Field List.
Note 39
You can also create a pivot table from an Access database like this:
1. Data…Get External Data…From Access.
2. Select the Access database file and then click Open.
3. Select the table or query to use for the data source and click OK.
4. Select PivotTable Report in the Import Data dialog and then click OK.
Note 40
Important
A pivot table doesn’t automatically update when the data source changes.
a local copy of data from an external data source. This means that you can still use the pivot table
even if the source database is down. If you are working with very large data sets you can switch off
the local storage of data by unchecking: PivotTable
Tools…Options…PivotTable…Options…Data…Save Source data with file.
3.3.5 Apply a simple filter and sort to a pivot table
1. Open Transactions-4 from your sample files folder (if it isn’t already open).
2. Select the Pivot Table worksheet (if it isn’t already selected).
3. Click inside the pivot table to display the Pivot Table Field List.
4. Remove the Genre and Title column Labels.
This has already been covered
5. Click the drop-down arrow next to Row Labels in cell A3.
Filter options appear.
These are very similar to the options that you learned to use in the lessons: Apply a simple
filter to a range and Apply a top 10 and custom filter to a range.
6. Filter the pivot table so that only female employees are shown.
Uncheck the check boxes next to each male employee (see sidebar).
Notice the filter icon in cell A3 showing that the pivot table has been filtered.
This is a very long winded way to filter out the male employees. In a real-world workbook
you’d probably create a Gender column in the source data containing the values M or F. You
could then filter by gender with a single check box.
7. Sort Employee names in Z-A order.
At the moment, the names are sorted in A-Z order.
i. Click cell A4.
When you click on any Employee name it makes Employee the active field.
v. Click and drag the border of each Employee name to move them to the desired
position. Look for the four headed arrow cursor shape before clicking the mouse.
Note 41
1. Open Transactions-5 from your sample files folder (if it isn’t already open).
2. Select the Pivot Table worksheet (if it isn’t already selected).
3. Drag the Genre field from the PivotTable Field List to the Report Filter list.
Notice that a filter has appeared at the top left of the pivot table (in cells A1 and B1):
iii. Make sure that the Select Multiple Items check box is checked.
v. Scroll down the list and check all of the June 2008 check boxes.
vii. Only goods sold in the Comedy genre during June 2008 are now displayed.
Of course there is. We can use a report filter to automate the whole task and print all 24 reports in
one operation.
1. Open Transactions-6 from your sample files folder (if it isn’t already open).
2. Select the Pivot Table worksheet (if it isn’t already selected).
3. Remove all filters.
There’s a quick way to remove all filters from a pivot table.
i. Click inside the pivot table to activate it.
ii. Click: PivotTable Tools…Options…Actions…Clear…Clear Filters.
4. Change the fields displayed by the pivot table so that they match the following:
You learned to do this in the Lesson: Understand pivot table rows and columns. Note that
the field automatically appears in the Column Labels list when you add more
than one field to the Values list.
Your pivot table now looks like this:
Because there is only one report filter, there’s only one choice. If you had multiple
report filters, you could choose which filter you wanted to use.
iii. Click the OK button.
Something amazing happens!
24 worksheets are instantly created, one for each employee.
iv. You can see that it contains a copy of the original pivot table with a filter set for
Chuck.
6. Print preview all worksheets.
i. Click on the first employee’s tab (West, Chuck)
DATA ANALYTICS USING EXCEL
4. Filter to only show the genres: Action, Adventure and Animation for employees: Chuck West,
Julie Spears and Dan Armstrong.
You learned how to do this in an earlier lesson
The pivot table changes to show coloured lines separating each row and column.
The other two options in the PivotTable Style options group are: Row Headers and
Column Headers. In the Dark 9 style, the column headers are shown in a contrasting
colour. The Column Headers check box allows you to switch this colour off. Some of
the other designs also show row headers (cells A6:A8) in a contrasting colour. If you
were using this type of design, you could switch this colour off with the Row Headers
check box.
7. Save your work as Transactions-7.
1. Open Transactions-7 from your sample files folder (if it isn’t already open).
2. Remove the existing style.
I. Click the pivot table to activate it.
II. Click PivotTable Tools…Design…PivotTable Styles…Light…None.
Notice that this style is different from the default style. The default pivot table style
is Light 16.
3. Create a custom pivot table style called Corporate by duplicating the Medium8 built in style.
You’ll usually find that modifying a duplicate of an existing style is easier than creating a style
from scratch.
I. Right-click on: PivotTable Tools…Design…PivotTable Styles…Medium…Pivot Style
Medium 8.
IV. Type the name Corporate into the Name text box.
III. Select Grand Total Column from the Table Element list.
IV. Click the Format button.
V. Select the Font tab.
This layout is useful when you need the report to take up the minimum amount of space on
screen or paper. Subsidiary fields are only slightly indented from their parent field.
5. Change the report layout to Outline Form.
Click:
PivotTable Tools…Design…Layout…Report Layout…Show in Outline Form
Outline Form is the classic pivot table layout that was the default in earlier versions of Excel.
It takes up more space but is more readable as each field has its own column label.
6. Change the report layout to Tabular Form.
Click:
PivotTable Tools…Design…Layout…Report Layout…Show in Tabular Form
This layout is very easy to read because it is similar to a regular Excel table with totals shown
at the bottom of each column.
7. Save your work as Transactions-9.
3. Add the Title field to the pivot table as a third-level row label.
Drag the Title field from the PivotTable Field List to the Row Labels list.
5. Format the Genre subtotal fields using the Total cell style.
I. Hover the mouse cursor over the left edge of the Biography Total label in cell B9.
II. Make sure you see the black arrow cursor shape and then click Transactions-9 to
select.
Notice that when you select the field all Genre subtotal cells are selected.
III. Click: Home…Styles…Cell Styles…Total.
1. Open Transactions-10 from your sample files folder (if it isn’t already open).
2. Remove the Genre and Title fields from the Row Labels list.
4. Change the new totals to show Average sales and Maximum sales for each employee.
I. Right-click anywhere in column C within the pivot table.
II. Click Value Field Settings… on the shortcut menu.
III. Select Average in the Summarize value field by list.
5. Format the Average of Total2 field so that it displays two decimal places.
I. Right-click anywhere in column C within the pivot table.
II. Click Number Format… on the shortcut menu.
Note 42
III. Click in the Formula text box and remove the zero, leaving only an = sign.
IV. Select Total in the Fields list and then click the Insert Field button.
V. The word Total is added to the Formula.
5. Change the names at the top of columns B and C to Sales and Bonus Due.
I. Click cell B5.
II. Type the new name Sales.
III. Press the <Enter> key.
DATA ANALYTICS USING EXCEL
IV. Use the same technique to change the name in cell C5 to Bonus Due.
6. Remove the Field Header (this is currently shown in row 4).
I. Click: PivotTable Tools…Options…Show/Hide…Field Headers.
The three items in the Show/Hide group are toggle buttons allowing you to add and
remove different pivot table artifacts. The pivot table is now well formatted.
The Values label has disappeared but so has the Employee label. If you wanted to
keep the Employee label you would have had to hide row 4 instead (See tip below).
Tip 21
In this lesson, we switched off the field headers in order to suppress the Values label in cell
B4. This had the side-effect of also removing the word Employee from cell A5.
If you wanted to keep the Employee label but suppress the Value label you would need to
hide row 4. To hide the row, right-click the row header (the number 4 on the left of the row)
and then click Hide from the shortcut menu.
Sometimes, you will want to perform a calculation upon a selected number of items within a field. In
this lesson’s example, you are interested in total sales for the Drama, Comedy and Action genres, as
they are your top sellers.
Calculated items provide a solution to this problem. In this lesson, we’ll add a calculated item to find
the total sales in these genres.
1. Open Transactions-12 from your sample files folder (if it isn’t already open).
2. Clear all filters from the pivot table.
I. Click: PivotTable Tools…Options…Actions…Clear…Clear Filters.
3. Remove all of the existing fields from the pivot table and replace them with the following:
4. Format the Sum of Total to show two decimal places with a thousand comma separator.
I. Right-click anywhere in column B within the pivot table.
II. Click Number Format… on the shortcut menu.
III. Click the Number category.
IV. Check the Use 1000 Separator (,) check box.
V. Click OK.
Your pivot table now looks like the one shown below.
5. Add a calculated item to show total sales for the genres: Drama, Comedy and Action.
I. Click any pivot table cell in column A.
II. Click: PivotTable Tools…Options…Tools…Formulas…Calculated Item…
The Insert Calculated Item dialog appears. This is very similar to the Insert Calculated
Field dialog. The dialog is confusing because it shows many fields and items that
would not be valid for the Genre field. They are not grayed out as you would expect.
IV. Select the Genre field and the Drama item and then click the Insert Item button.
The formula changes to include the Drama item.
VI. Add the Comedy and Action items in the same way so that your formula is the same
as the following:
Notice that this addition has corrupted the Grand Total as Drama, Comedy and
Action are included in the Grand Total twice.
6. Filter the individual Drama, Comedy and Action fields so that they are no longer shown or
included in the Grand Total.
Because the Field Headers are currently switched off, you cannot apply a filter.
I. Click: PivotTable Tools…Options…Show/Hide…Field Headers.
II. The Genre field header appears in cell A4.
Another solution to this problem would be to create a group for these three genres. The pivot table
could then show group totals. We’ll push things a little further, in this lesson, by placing each of the
genres into three groups:
4. Format the Sum of Qty field so that it shows 0 decimal places and a comma separator for
thousands.
I. Right-click anywhere in column B within the pivot table.
II. Click Number Format… on the shortcut menu.
III. Click the Number category.
IV. Select the Number category and set 0 decimal places with a thousand separator.
III. Right-click on any of the selected fields and click Group in the shortcut menu.
The fields are grouped:
6. Change the Genre2 label to Category and the Group1 label to Action, Comedy & Drama.
The default names are not very descriptive. Single-click (be careful not to double-click) on
each field (cells A4 and A5) and then type in the new labels.
7. Create the Crime, Biography & Fantasy group and the Adventure, Sci Fi, Thriller & Animation
group. Do this in exactly the same way. (This time you will select the Genres in column B).
8. AutoSize column A and collapse all categories. This was covered in the Lesson: Create a
grouped pivot table report. Your pivot table should now look like this:
In previous versions of Excel, this feature was so well hidden that most Excel users didn’t even know
it was there. Things are a little better with the new Ribbon interface.
1. Open Transactions-14 from your sample files folder (if it isn’t already open).
2. Remove all of the existing fields from the pivot table.
You’ll often want to remove all fields and filters from your pivot table to start again. To do
this, click: PivotTable Tools…Options…Actions…Clear…Clear All
3. Add the following fields to the pivot table.
Sales are now shown for every employee and for every date. Sales are summarized by day
but it is more likely that you will want to show sales by week, month, quarter or year.
Note 43
(The order is important. Age must come before Name). The pivot table now groups
employees by age.
Where two employees are the same age, they are grouped together. The challenge for this
lesson will be to group employees into different age bands.
5. Group the pivot table into the age bands: Under 25, 25-34, 35-45 and Over 45.
I. Right-click any of the ages in column A (for example: cell A6).
II. Click Group from the shortcut menu.
The Grouping dialog is displayed.
1. Open Transactions-15 from your sample files folder (if it isn’t already open).
2. Remove all of the existing fields and filters from the pivot table (including the calculated
item added in the last lesson).
DATA ANALYTICS USING EXCEL
You’ll often want to remove all fields and filters from your pivot table to start again. To do
this, click: PivotTable Tools…Options…Actions…Clear…Clear All
3. Add the following fields to the pivot table.
4. Format the Sum of Total field to show two decimal places and thousand separators.
Sales are now shown for every employee and for every genre.
You can see at a glance that Alfred Hawking does very well with sales in the Action
genre, and that Paul Goodman is our star performer in the Drama genre. We should
keep Michael Hicks and Julie Spears away from Science Fiction sales!
6. Save your work as Transactions-16.
This Expert Skills course assumes that you already understand normal Excel charts.
When you create a pivot chart from a pivot table, it is important to realize that the chart always
matches the data shown in the pivot table. You make changes to the source data of the chart by
modifying the pivot table underpinning it.
1. Open Transactions-16 from your sample files folder (if it isn’t already open).
2. Change the Sum of Total field so that it displays cash values rather than a percentage of the
total.
I. Right-click on any of the percentage values in the pivot table.
II. Click Value Field settings in the shortcut menu.
The Value Field Settings dialog is displayed.
III. Click the Show values as tab.
While this is sometimes what you want, most of the time you’ll want to place your
chart into a worksheet of its own (see note below).
6. Move the chart to its own worksheet.
DATA ANALYTICS USING EXCEL
Note 44
This will also confirm your understanding of many of the skills learned in this session.
1. Open Transactions-17 from your sample files folder (if it isn’t already open).
2. Add a new worksheet and name it: Summary.
3. Type Sales Summary into cell B1.
4. Apply the Title style to cell B1.
I. Click: Home…Styles...Cell Styles.Titles and Headings…Title.
5. Embed a pivot table starting at cell B3 to show sales by Customer.
I. Click in cell B3.
II. Click: Insert…Tables…PivotTable.
3.3.21 Exercise
1. Open Film Sales-1 from your sample files folder.
2. Convert the range to a table named Data.
3. Create a pivot table from the Data table.
4. Add Row Labels and Values so that your pivot table looks like this:
5. Re-format the values in the pivot table, change the text in the header, and hide row 3, so
that your pivot table looks like this:
6. Add a calculated field to calculate the average cost per unit for each carrier formatted to
two decimal places.
7. Embed a second pivot table starting in cell A11 of the same worksheet that will display sales
by studio in an attractive format.
4 MODULE 4
4.1 What-if analysis
The concept of “What If” is very simple. A business may wish to know what will happen in a given set
of circumstances (called a scenario). For example, a simple scenario might be: “What if I reduced my
profit margins by 5% and my sales increased by 20%?” Excel provides several tools that are geared to
more complex scenarios. In this session you’ll learn how to use these tools effectively.
In this lesson we’ll use a data table to list the monthly repayments for a loan at different interest
rates.
This is a simple worksheet that calculates four result values from four input values. When
performing what-if analysis, it is a good idea to separate the input values from the result
values on your worksheet.
The worksheet uses the PMT function that was covered in: Lesson: Use the formula palette
and the PMT function.
During the last 20 years, interest rates have never dropped below 2.5% or increased to more
than 15.5%.
Based upon the assumption that future rates will stay in this range, we will create a data
sheet to show how potential changes in interest rates will affect monthly payments.
DATA ANALYTICS USING EXCEL
2. Create a one variable (single input) data table to display all result cells for interest rates
between 2.5% and 15.5% in half percent increments.
a. Type Interest % into cell D3.
b. Type Monthly Payment into cell E3.
c. Type Total Payments into cell F3.
d. Type Total Interest into cell G3.
e. AutoSize columns D, E, F and G so that all of the headers are readable.
f. Type 2.5% into cell B7.
When you create a data table, you should always put the lowest input value into the
source table. You’ll see why in a moment.
g. Put formulas in cells D4:G4 that refer to the relevant input and result cells. The
correct formulas are shown below:
Excel 2013 Data tables have a problem with certain formulas in the left-hand
column. For this reason you need to Copy the values in cells D4:D30 and then Paste
Special them back to the same location as Values.
Because the interest rates are shown in column D, Excel must change the value in
cell B7 to the value in column D in order to calculate values for columns E, F and G.
The data table is populated to show all result cells for all interest rates.
You are now able to change any of the Input Cells to explore the effect of different
Loan Amount, Interest Rate, Deposit or Term values.
Single-input data tables can have the input cell along rows or columns
It is also possible to place the result cells along the left of the data table and the input cells along
the top.
In this case, you would specify a Row input cell rather than a Column input cell in the Data Table
dialog.
Note 46
This often confuses, because you’ll find no reference to a TABLE function in the Excel help.
You’ll also find that you are unable to manually create a TABLE function.
The TABLE function is simply Excel’s “behind the scenes” way of implementing data table
functionality. The only way you can insert a TABLE function into a worksheet is by creating a data
table.
Note 47
You cannot change or delete a cell in a data table. If you try to do this, Excel will produce an error
message. If you need to remove cell in a data table, you must delete the entire table.
However, in a two-input data table, input cells are arranged along both the top and the left-hand
side of the table.
In this lesson we’ll use a two-input data table to show monthly repayments for different loan
amounts and different interest rates.
1. Open Mortgage-2 from your sample files folder (if it isn’t already open).
2. Create a new worksheet and name it: Variable Interest and Capital.
3. Copy cells A1:B13 from the Variable Interest worksheet and paste them into the same cells
in the Variable Interest and Capital worksheet.
4. AutoSize columns A and B so that they are wide enough to display all values.
5. Create rows for your data table in cells E3:L3 showing capital amounts from 125,000 to
300,000 in increments of 25,000.
a. Type 125,000 into cell E3.
b. Type 150,000 into cell F3.
c. Select cells E3:F3 and AutoFill to cell L3.
6. Create column labels for your data table in cells D4:D30 showing interest rates from 2.5% to
15.5% in increments of 0.5%.
a. Type 2.5% into cell D4.
b. Type 3% into cell D5.
c. Select cells D4:D5 and AutoFill to cell D30.
7. Format cells D4:D30 to show one decimal place.
a. Select cells D4:D30.
b. Click: Home..Number..Decrease Decimal.
8. Put a formula in cell D3 that will reference the Monthly Repayment result cell.
9. Apply the Note cell style to cells D3:D30 and cells D3:L3.
a. Select cells D3:D30 and cells E3:L3.
b. Click: Home..Cell Styles..Note.
10. Create a two-input data table to show monthly payments for each capital amount and
interest rate.
a. Select cells D3:L30.
b. Click: Data..Data Tools..What-If Analysis..Data Table...
Note that you could take the view that the amount financed in cell B10 is the
operative row input cell. I’m using cell B4 as it represents how much capital you
would have available if your lender demands a 10% deposit.
c. Enter these values into the dialog and then click OK.
This will format the numbers with a thousand comma separator and two decimal
places.
The value in cell D3 looks a little untidy. If you’d like it to become invisible see the tip
below.
You will often want to hide numbers or text in specific cells. A common way of doing this is to
format the cell as white text upon a white background. A better solution is to create a custom
format consisting of three semicolons.
4.1.2 Scenarios
4.1.2.1 Define Scenarios
When you create a set of input values, it is referred to as a scenario.
Forecasted sales for next month are: 1,500 Grommets, 4,300 Sprockets, 3,100 Widgets and 2,800
Flugel Valves.
Sometimes, you will have several different scenarios that you want to compare side-by-side. For
example, you may ask your salesmen for “worst case, expected case and best case” scenarios.
Excel’s Scenario Manager is designed to allow you to easily compare these scenarios side-by-side.
Notice that this worksheet has been grouped to show four sets of values:
As you’ll see later, in Lesson: Create a scenario summary report, the Scenario Manager
expects you to define range names for input and result cells in order to correctly display
scenario summary reports.
The Scenario Manager uses the term Changing cells to refer to Input Cells.
g. Click the Add button and then use the same technique to add the Expected Case and
Best Case scenarios.
h. Click the OK button.
4. Use the Scenario Manager to view result cells for each scenario.
a. Select one of the cases in the Scenarios list.
b. Click the Show button to display the scenario on the worksheet.
c. Select a different case and click the Show button.
d. Click the Close button to close the Scenario Manager.
5. Save your work as Profit Forecast-2.
Note 48
Excel is able to display a drop-down list of defined scenarios from the Quick Access Toolbar. This is
another of those features that cannot be accessed in any other way, as it doesn’t appear anywhere
on the Ribbon.
You can then choose a scenario to display the result cells on the worksheet.
DATA ANALYTICS USING EXCEL
Note 49
If you try to define more than 32 changing cells, Excel will display an error message
1. Open Profit Forecast-2 from your sample files folder (if it isn’t already open).
2. Open the Scenario Manager.
a. Click: Data..Data Tools..What-If Analysis..Scenario Manager…
This dialog asks which result cells should be displayed on the report.
Notice that the report is shown as an outline and that it is possible to collapse and
expand the outline by clicking the plus and minus buttons or on the numbers at the
top left corner.
You can now see how important it was to define named ranges for the input and
result cells. Without these the report would show cell references rather than
descriptive names such as Flugel_valves.
This time Excel hasn’t done such a good job. You’d need to spend a little time re-
formatting this report!
Merging scenarios
Excel allows you to merge scenarios from one or more other workbooks.
Imagine that you send a worksheet out to three salesmen: Tom, Dick and Harry.
Your salesmen are well trained in Excel and know how to define a scenario.
You instruct each of them to forecast their sales by completing the input cells on their worksheet.
They then name a scenario with their own name which references the input cells.
When you receive their workbooks, you merge them with your summary workbook like this:
Make sure that the Tom, Dick Harry, and Summary workbooks are open (they are in the sample
files if you want to work this through).
1. Make sure you are viewing the Summary workbook.
2. Click Data..Data Tools..What-If Analysis.. Scenario Manager.
3. Click the Merge... button.
4. Select Sheet1 of the Tom workbook.
5. Click OK.
6. Do the same for Dick and Harry.
The three scenarios Tom, Dick and Harry are now available in the Summary workbook.
4.1.3 Use Goal Seek
It is very easy to view result values by changing input values. You simply type the new values into the
input cells.
In the above worksheet, I wanted to know the monthly repayment for a 250,000 loan with a 10%
deposit over 10 years at 2.5%. I simply typed the values into the input cells and viewed the results in
the result cells.
Consider the case where you want to know the maximum Loan Amount if you can only afford a
monthly payment of 1,000. This is more difficult because the result cells contain formulas rather
than values.
By using Goal Seek, Excel will change one (and only one) input cell so that the desired value is shown
in one result cell.
There’s a much more complex tool called Solver (you’ll learn about this later in: Lesson 6-6: Use
Solver), that is a more advanced goal seek tool, able to automatically set multiple input cells.
For now, we’ll examine the simple and extremely useful goal seek tool.
We want to set the Monthly Repayment (B11) to the value 1,000 by changing the
Complete the dialog as follows: Loan Amount (B4).
d. Click OK.
e. Click OK.
The maximum Loan Amount I could raise will be 247,675 if I can only afford 1,000
per month. I could, of course, have also used goal seek to change any of the other
input cells. The key limitation of Goal Seek is that it can only change one input cell.
Most of the business people that take my courses have no use for Solver. The tiny percentage that
do often get wildly excited about the potential of this tool.
Because Solver is really an external tool (installed as an add-in) rather than a core part of Excel,
this course doesn’t explore some of the more exotic features of this remarkable tool.
There are a huge number of tutorials covering some extremely advanced uses of Solver at:
http://www.solver.com
You’ll find all you could ever want to know about Solver there.
What is Solver?
Conceptually, Solver is similar to Goal Seek. While Goal Seek can only change one input cell to set a
value in one result cell, Solver can change any number of input cells. This makes the tool more
complex.
You can also define a set of rules (called constraints) that Solver needs to observe when finding a
solution.
This worksheet models a bicycle manufacturing company. The company manufactures four
different types of bicycle but has a limited number of parts available.
a. Cells B4:E4 are the input cells (or changing cells) for the worksheet. They define how
many bicycles of each model will be manufactured.
b. The parts needed to manufacture each type of bicycle are shown in cells B7:E11. For
example, a Street Bike needs 2 wheels, 1 steel chassis and 1 set of derailleur gears.
c. Column I shows how many parts are available.
d. Cells B14:F14 show the profit for each bicycle type along with the total profit for all
bicycle types.
Our challenge is to maximize profit by manufacturing the optimum number of each type of bicycle.
Solver now appears on the Ribbon’s Data tab in a new Analysis group:
3. Open Solver
DATA ANALYTICS USING EXCEL
Click: Data..Analysis..Solver.
Solver appears.
4. Let Solver know which the Changing (Input) cells are and which the Target (Result) cell is.
We are telling Solver to maximize profit by changing the Input Cells (or Changing Cells)
B4:E4.
c. Click Add.
d. Set up a second constraint as follows:
This tells Solver that it cannot use more parts than are available.
e. Click OK.
6. Solve the problem.
a. Click the Solve button.
DATA ANALYTICS USING EXCEL
This worksheet uses the SUMPRODUCT function to calculate the Parts Needed in column G and the
Total Profit in cell F14.
SUMPRODUCT is an array function. Array functions accept ranges as arguments and then perform
calculations using each value in the range.
= SUMPRODUCT($B$4:$E$4, B7:E7)
This will perform the calculation:
B4*B7+C4*C7+D4*D7+E4*E7
Note 52
Solver is a product developed by Frontline Systems who have now distributed over 500 million
copies of their product to users. That’s a lot of software!
As well as Excel’s Solver, Frontline also developed the solvers included in Lotus 1-2-3 and Quattro
Pro.
Every copy of Excel sold since 1990 has included Frontline’s Solver.
Fontline also produce a more advanced version of Solver (available at extra cost) called Premium
Solver. There’s also a Risk Solver product that enables Excel to model Monte Carlo simulations.
the appropriate statistical or engineering macro functions to calculate and display the results in an
output table. Some tools generate charts in addition to output tables.
5 MODULE 5
5.1 Security
5.1.1 Hide and Unhide Worksheets, Columns and Rows
1. Open Human Resources-1 from your sample files folder.
2. Hide the Headcount & Salaries worksheet.
The Payroll worksheet depends upon the Headcount & Salaries worksheet in order to
calculate each employee’s hourly rate.
Because this data is sensitive, you may decide to hide the entire Headcount & Salaries
worksheet.
a. Right-click any worksheet tab (at the moment the only visible worksheet tab is
Payroll).
b. Click Unhide on the shortcut menu.
You can see that this is not a good way to hide confidential information, as any
knowledgeable user can simply unhide the worksheet (see note below).
4. Hide rows 3:6, rows 19:23 and row 9 on the Payroll worksheet.
Perhaps you would like to print out the Payroll worksheet for the floor manager so that each
employee’s hours can be reviewed.
For this reason, you are going to hide the confidential rows on the Payroll worksheet before
printing.
The payroll no longer shows any financial values. It would now be possible to print
the worksheet without showing the hidden rows.
b. Right-click any of the row headers (the numbered buttons on the left of the
worksheet).
c. Click Unhide on the shortcut menu.
There is no need to save this worksheet as it has not been changed in any way.
Note 53
The right-click method is much faster than using the Ribbon but here’s how it can be done:
To hide a worksheet:
To Unhide a worksheet:
Note 54
There is no password associated with hiding and unhiding a worksheet, row or column. A
knowledgeable user can easily unhide any hidden item.
If you need to hide items more securely, it is possible to protect the structure before distributing a
workbook.
When this is done, it isn’t possible to unhide and view the hidden items unless you know the
password.
Protecting the structure of a workbook will be covered in: Lesson: Control the changes users can
make to workbooks.
Tip 23
A hidden column is simply a column whose width has been set to zero. You can quickly hide a row
or column by dragging its border to make it so narrow that it is no longer visible.
Sometimes you may find that you are continuously hiding and unhiding the same rows and columns
in order to print selected parts of a worksheet. When you notice that this is happening, you have an
ideal candidate for a custom view.
Custom views allow you to save and recall worksheet layouts that have hidden columns and rows.
1. Open Human Resources-1 from your sample files folder (if it isn’t already open).
2. Select the Payroll worksheet.
3. Save the current view as HR.
DATA ANALYTICS USING EXCEL
Notice that custom views don’t only save hidden rows and columns. Custom views
also save Print settings, including any Page Layout settings, along with any filters
that are currently applied to the worksheet. This includes the zoom factor, window
sizes and positions, the currently active cell and the current worksheet view
(Normal, Page Layout or Page Break Preview).
Nothing seems to have happened but you have, in fact, stored a view with all rows
and columns visible.
4. Hide rows 3:6, rows 19:23 and row 9 on the Payroll worksheet.
This was covered in: Lesson: Hide and unhide worksheets, columns and rows.
Excel 2013 custom views can’t be used in any workbook that contains a table (though I expect that
this will be fixed in a future version).
If there’s a table anywhere in the workbook, the Custom Views button will be grayed out for all
worksheets.
You can work-around this limitation by using range names in place of tables when you really need
the Custom Views feature.
1. Open Human Resources-2 from your sample files folder (if it isn’t already open).
2. Protect the workbook with a password that will prevent other users from opening it.
a. Click: Office Button..Save As..Excel Workbook.
(If you are using the Windows operating system earlier than Windows 8, your screen
may differ slightly from the screen shot).
See the secure passwords note below for important information about choosing an
appropriate password.
See note below for a discussion of the Always Create Backup and Read-only
recommended check box options.
d. Click OK.
Excel reminds you not to forget the password and prompts for it again to protect
against accidental typing errors.
Follow the same procedure as you did when adding a Password to open but, this time
specify a Password to modify.
This doesn’t have the effect you would expect. You’ve opened the workbook
without a password and are able to change it.
Surprisingly, Excel will only disallow you from saving the workbook with the same name as
the password-protected workbook. It is quite happy for you to make a copy and even
prompts you to do so when you attempt to save the file.
Secure passwords
Hacking tools (freely available on the Internet) commonly use five methods to discover passwords:
1. Dictionary attack
In a matter of seconds the tool tries every word in the dictionary. For this reason your
password should never be a real word such as London.
2. Dictionary + numbers
The tool makes several passes through the dictionary, appending a sequential number to
the front or back of the password. For this reason, your password should never be a real
word with leading or trailing numbers, such as London99 or 99London.
3. Reverse words
The tool tries every word in the dictionary spelled backwards.
Words with the letter O replaced with a zero
4. Brute force attack
The tool tries every possible combination of the letters of the alphabet. This takes a
maximum of ten hours to crack a seven letter password such as xcrdkfh.
It would currently take a maximum of 178 years to crack a nine letter password that uses both
upper and lower case (though this will reduce in the future as computer power increases).
For ultimate security against brute force attacks, include upper and lower case letters, numbers,
and symbols in your passwords. The best approach is to create a password from a phrase such as:
“I like to ride my children to school at 20 MPH”. This gives the extremely secure password:
Iltrmcts@20MPH
Note 57
Even if you choose a secure password that is nine or more characters long (such as
IltrmHm@100MPH), there are tools freely available on the Internet that can crack most of the
Excel 2013 worksheet protection passwords in minutes.
DATA ANALYTICS USING EXCEL
Currently, only the password to open is not easily cracked. The password to open is encrypted
using AES 128 (Advanced Encryption Standard with a 128-bit key).
Note 58
The Always Create Backup check box provides you with an escape route if you need to return to
the previous version of the workbook.
A copy of the old workbook is saved every time you save, so that you always have two copies of
each workbook. One copy is a Microsoft Excel Backup file with the file extension .xlk.
If you check the Read-only recommended check box, the user is presented with a dialog when
opening a protected workbook. The dialog suggests that the book be opened read-only.
If the user ignores this suggestion, a read/write copy will be opened. As you discovered in this
lesson, this copy cannot be used to over-write the protected file but can be used to create a new
file with a different name.
Some worksheets are intended to be viewed on-screen at a specific size. In this case, you need to
prevent your users from re-sizing the worksheet windows. This is called protecting the Windows of a
workbook.
In this lesson, we’ll discover how to protect a workbook’s structure, windows, or both.
1. Open Human Resources-3 from your sample files folder (if it isn’t already open).
2. Display the Hours Worked (Female) custom view.
This was covered in: Lesson: Hide and unhide worksheets, columns and rows.
The option to disable re-sizing or moving the worksheet window was deprecated in
Excel 2013.
Because you checked the Structure check box you are also unable to insert, delete,
rename, move, hide or unhide any of the worksheets in this workbook.
Protection is removed.
This was covered in: Lesson: Hide and unhide worksheets, columns and rows.
4. Re-size columns B:O so that they are just wide enough to display their contents:
The challenge this time will be to prevent the user from changing any value other than those
in the yellow shaded cells (cells B12:O16).
We will solve this problem by unlocking these cells and then protecting the worksheet. This
will only allow the user to enter values into the unlocked cells.
All cells on a worksheet are (by default) locked. You are able to type values into them
because the worksheet is not yet protected.
In order to prevent the user from changing any cell except cells B12:O16 we need to do two
things:
Unlock the cells that you want the user to be able to change.
Protect the worksheet.
When you protect a worksheet, it is no longer possible to change the contents of a locked
cell.
The default settings allow the user to select (but not change) the contents of locked
cells. This normally makes sense as you want the user to be able to copy and paste
any part of the worksheet.
In this case, however, it creates a huge security problem as the user can easily copy
the entire worksheet, paste it into a new worksheet, and then unhide the hidden
rows.
For this reason, we want to prevent the user from selecting locked cells.
Notice that by default, the user is prevented from doing many more things to the
worksheet (such as formatting cells). You can selectively allow these actions by
checking the appropriate check box.
c. Enter a password.
d. Click the OK button.
7. Test the protected worksheet.
You are unable to change (or even select) any of the locked cells but you can select and
change any of the unlocked cells.
Do this in the same way that you unlocked the cells, but this time, check the Locked check box
(instead of un-checking it).
Note 59
You can keep your formulas secret with the Hidden attribute
If you set the Hidden attribute on the Format Cells Protection tab, users cannot see any of your
formulas.
Even if a cell is unlocked, the formula does not display on the formula bar when the cell is selected.
This could be used if the formula used to calculate a value was a “trade secret”.
In the same way as for unlocked cells, this only takes effect when the worksheet is protected.
Tip 24
Excel is often used to create forms (such as booking forms). The form is sent to the user by e-
mail and the user completes and returns it.
This type of form becomes much easier to use if you do the following:
Unlock the cells that the user should type data into.
Protect the worksheet making sure that only the Select unlocked cells option is
checked.
When this is done, the user can use the <Tab> key to navigate through all of the cells in the form
that need to be completed.
Tip 25
If you protect a workbook without unlocking any cells, you have effectively created a read-only
workbook.
If you also want to prevent the user from copying and pasting the contents, you should also un-
check the Select locked cells check box. Note that this will not prevent the user from copying an
image of the worksheet using a third-party tool.
I have deliberately used very insecure passwords in order to save you the effort of typing long (and
more secure) ones. If security was important, you would use secure passwords.
You are now able to freely change any value in cells B12:O16 for as long as the
workbook stays open.
You are now able to freely change any value in cells B4:B6, B9:O9 or B12:O16 for as
long as the workbook stays open.
You can allow access based upon the Windows log-in password or user group
You can also use your existing windows passwords and user groups to allow access to specific
ranges of cells.
You may also worry that the workbook may have been altered by somebody since the author sent it
to you.
If a workbook is digitally signed, it confirms the identity of the author. Excel will also warn the
recipient if it has been changed since the author signed it.
Digital certificates are of great use when you need to distribute workbooks that contain macros
within an organization. Macros can contain destructive macro viruses and you wouldn’t ever want to
open a workbook containing macros without being absolutely sure of its origin.
1. Create your own digital certificate. This isn’t very secure, as it is easy to forge a self-certified
digital certificate. When another user opens a workbook with a self-certified signature it will
display the message: “This document contains invalid Signatures”
This isn’t likely to inspire a great deal of confidence in the recipient. In fact, I’d go so far as to
say that a self-certified digital certificate has no value as it doesn’t really increase security at
all.
2. Buy a certificate from a trusted third party such as VersiSign. Third-party certificates
provide a high level of security as they are certified to be genuine by an outside agency.
When the user opens a workbook, Excel will confirm that the certificate is genuine by
contacting the third-party’s server. Most third-party subscriptions cost between US$100 and
US$500 per year.
5.1.8 Exercise
1. Open Selling Price Calculator-1 from your sample files folder.
2. Create an attractively formatted single input data table in cells D3:F18 to display the Gross
Profit and Gross Profit Percent that would result from a Retail Price of $17.95 to $24.95 in
increments of $0.50.
7. Create a Scenario Summary report to show Sales, Total Cost, Gross Profit and Gross Profit
Percent for each scenario.
8. Protect the Selling Price Calculator worksheet so that only cells B4:B7 (the cells shaded
Orange) can be changed.
9. Save your work as Selling Price Calculator-2.
When you record a macro, the macro recorder records all the steps required to complete the actions
that you want your macro to perform. These steps can include typing text or numbers, clicking cells
or commands on the ribbon or on menus, formatting, selecting cells, rows, or columns, and dragging
your mouse to select cells on your spreadsheet. The commands for recording, creating, and deleting
macros are available on the Developer tab on the Ribbon.
Note: The first character of the macro name must be a letter. Subsequent characters can be
letters, numbers, or underscore characters. Spaces cannot be used in a macro name; an
underscore character works well as a word separator. If you use a macro name that is also a
cell reference, you may get an error message that the macro name is not valid.
5. To assign a Control (Ctrl) combination shortcut key to run the macro, in the Shortcut key
box, type any lowercase letter or uppercase letter that you want to use.
The shortcut key will override any equivalent default Excel shortcut key while the workbook
that contains the macro is open.
6. In the Store macro in list, select the workbook where you want to store the macro.
If you want a macro to be available whenever you use Excel, select Personal Macro
Workbook. When you select Personal Macro Workbook, Excel creates a hidden personal
macro workbook (Personal.xlsb) if it does not already exist, and saves the macro in this
workbook. In Windows 7 and Windows Vista, this workbook is saved in the C:\Users\user
name\AppData\Local\Microsoft\Excel\XLStart folder. In Microsoft Windows XP, this
workbook is saved in the C:\Documents and Settings\user name\Application
Data\Microsoft\Excel\XLStart folder. Workbooks in the XLStart folder are opened
automatically whenever Excel starts. If you want a macro in the personal macro workbook to
be run automatically in another workbook, you need to also save that workbook in the
XLStart folder so that both workbooks are opened when Excel starts.
10. On the Developer tab, in the Code group, click Stop Recording .
Note: Modules are automatically created for all sheets in the workbook.
3. In the code window of the module, type or copy the macro code that you want to use.
4. To run the macro from the module window, press F5.
5. In the Visual Basic Editor, on the File menu, click Close and Return to Microsoft Excel when
you finish writing the macro.
1. Open the workbook that contains the macro that you want to copy.
2. On the Developer tab, in the Code group, click Macros.
3. In the Macro name box, click the name of the macro that you want to copy.
4. Click Edit.
5. In the code window of the Visual Basic Editor, select the lines of the macro that you want to
copy.
Tip: To copy the whole macro, include the Sub and End Sub lines in the selection.
You may not be able to edit your Personal Macro Workbook file (Personal.xlsb) because it is a hidden
workbook that is always open. You need to first unhide it by using the Unhide command. You can
also open Personal.xlsb in the Visual Basic Editor by pressing Alt+F11.
1. On a worksheet, right-click the object, graphic, or control to which you want to assign an
existing macro, and then click Assign Macro.
2. In the Macro name box, click the macro that you want to assign.
Open the workbook that contains the macro that you want to delete.
If the macro that you want to delete is stored in the personal macro workbook
(Personal.xlsb), and this workbook is hidden, do the following to unhide the
workbook: