EXCEL Formulas Bible
EXCEL Formulas Bible
EXCEL Formulas Bible
Contents
Formulas ....................................................................................................................................................... 3
VLOOKUP................................................................................................................................................... 3
COUNTIFS .................................................................................................................................................. 4
COUNT................................................................................................................................................... 4
IF ............................................................................................................................................................ 5
COUNTIF ................................................................................................................................................ 5
COUNTIFS .............................................................................................................................................. 6
Filters............................................................................................................................................................. 7
Ribbon Tour............................................................................................................................................... 7
Quick Filtering ........................................................................................................................................... 7
Filtering by Multiple Criteria ..................................................................................................................... 9
Saving the Filtered Data .......................................................................................................................... 11
Performing Calculations on Filtered Data ............................................................................................... 12
PivotTables .................................................................................................................................................. 13
Defined.................................................................................................................................................... 13
Basic PivotTable Data .............................................................................................................................. 14
Inserting a Pivot Table............................................................................................................................. 14
PivotTable Geography ............................................................................................................................. 15
Building a PivotTable Report – Part One................................................................................................. 16
Adding row labels, adding column data, changing formulas in columns, changing headers & number
formats ................................................................................................................................................ 16
Building a PivotTable Report – Part Two ................................................................................................ 24
Adding multiple row labels, collapsing and expanding, drill down to data, sorting, & refreshing ..... 24
Building a PivotTable Report – Part Three .............................................................................................. 26
Grouping by dates, grouping by ranges, show items with no detail, show values in empty cells,
grouping across columns .................................................................................................................... 26
Building a PivotTable Report – Part Four ................................................................................................ 33
User defined groups, adding/removing subtotals .............................................................................. 33
Building a PivotTable Report – Part Five ................................................................................................. 35
Using formulas on pivoted data .......................................................................................................... 35
Building a PivotTable Report – Part Six ................................................................................................... 37
Displaying multiple row labels in columns, or tabular form. .............................................................. 37
Other Cool Things to do with a Pivot Table – Part Seven ....................................................................... 39
Report Filters....................................................................................................................................... 39
Report Slicers ...................................................................................................................................... 40
Expanding Filter Results to Individual Tabs ........................................................................................ 41
Formatting as a Table - Part Eight ........................................................................................................... 41
2
Formulas
VLOOKUP
The VLOOKUP function searches vertically (top to bottom) the leftmost column of a table until a value that
matches or exceeds the one you are looking up is found.
The elements being looked up must be unique and must be arranged or sorted in ascending order; that is,
alphabetical order for text entries, and lowest-to-highest order for numeric entries.
An example of the formula is: VLOOKUP(E2,D2:M3,2,TRUE) The English translation is using the value found in the
cell E2, look in the range of D2 to M3 row by row. If you find a value that matches or exceeds the value in E2,
using that row, go over 2 columns to the right, grab the value there and bring it back.
TRUE
If it doesn’t find an exact match, it will use the last item before it got greater
Alphabetical: Looking for Cat. If elements are Apple, Bird, Carpet, Dog; then Carpet
would be returned because Dog exceeds Cat alphabetically.
Numeric: Looking for 5.25. If elements are 3.0, 4.0, 5.0, 6.0, 7.0, then 5.0 would be used.
The last number before 5.25 was exceeded.
FALSE
Alphabetical: Looking for Cat. If elements are Apple, Bird, Carpet, Dog; then #N/A would
be returned.
Numeric: Looking for 5.25. If elements are 3.0, 4.0, 5.0, 6.0, 7.0, then #N/A would be
returned because there is no exact match.
3
COUNTIFS
Recall quickly the COUNT and IF commands.
COUNT
The COUNT function counts the number of cells that contain numbers and counts numbers within the
list of arguments.
Continuing on with our SUM formula from above, let’s not only add up the values of the range A1:A4,
but let’s count how many numbers are included within the range, i.e. how many cells within the range
has a value in it.
The formula is =COUNT(A1:A4). The English translation is count how many cells within the range has a
value in it and display the result.
4
If you are trying to count text, use the COUNTA formula which counts the non-blank cells.
IF
The formula makes a statement/question, if the answer is true then one response is obtained. If the
answer if false, then another answer is obtained.
Continuing on with our SUM formula from above, let’s add some verbage to emphasize whether the
result is greater or less than twenty.
The formula is =if(A5<20,”Amount is less than twenty”,”Amount is more than twenty”). The English
translation is if the value found in A5 is less than twenty THEN display the comment ‘Amount is less than
twenty’ ELSE display the comment ‘Amount is more than twenty’.
COUNTIF
The COUNT function counts the number of cells in a range, that meets single criteria.
5
COUNTIFS
The COUNT function counts the number of cells in a range that meets multiple criteria.
6
Filters
Ribbon Tour
Quick Filtering
The secret to filtering is not to have a space between your titles and your data. In fact, Excel is so smart, that you
do not even have your data selected, but may if you prefer.
7
By selecting the chevron to the left of Vendor Name, a dialog
box appears displaying all unique text filters found in the range
as well as other common sort icons.
If you only want a particular filter, deselect the (Select All) box
and check the filter you desire.
In the below screen shot, Kendell Kilborn is selected. Notice the hidden rows to the left. Those represent
data lines for mileage paid to individuals other than Kendell. No data is lost, it is just currently hidden.
8
Filtering by Multiple Criteria
The filtering tool is fine when you only want one item. However the power of the advance filter tool really shines
when you want to sort by multiple criteria. There are several thou shalts of advanced filtering.
1 The headers in the criteria range must be exactly as they are in the list range
2 l must be at least one blank row between the criteria range and the list range
There
Create a criteria range by inserting a few rows and copying the header from the data range.
1 Although not required, it is often best to have the range above your data for simplicity.
The list range most likely will be your data. If not, you will need to correct it.
5
Select OK
7
9
4
1 2
10
Saving the Filtered Data
Now that the data has been filtered it would be great to save it so you can manipulate it further. To do
so is a rather straight forward process. Basically you will go to where you want to save it, Sheet2 in our
example, and go through the filtering process that we did above with just a couple of twists.
On the destination worksheet (Sheet2 for example) place the cursor in a blank cell.
1
2
Select the Advanced icon with your left mouse button.
Under Action, select copy to another location
3
11
4
2 COUNT 8 STDDEVP
3 COUNTA 9 SUM
4 MAX 10 VAR
5 MIN 11 VARP
6 PRODUCT
12
An example of the formula is: =SUBTOTAL(9,E12:F19) The English translation is using the ninth
subtotal function, which is SUM, add up all of the data within the range that is selected by the filter.
For comparison, included is the SUM function for the same range which brought back the total for all
of the data cells, hidden or displayed.
PivotTables
Defined
The foundation of what is a PivotTable report is explained as follows:
As long as you can connect to the data, whether it be locally in the same workbook or remotely
in other locations, you can built PivotTable reports that rearrange the raw data and change
it into meaningful information
A pivot table is an interactive way to quickly summarize large amounts of data; to analyze numerical
data in detail and to answer unanticipated questions. They are especially designed for:
13
Thou Shalts in PivotTable Land
Best to have the pivot table on a separate worksheet so it does not accidently clobber the
3
data
5 Best to format your area as a table, especially when you will be adding data to it. The table
is automatically expanded when data is added to the next row. Now when you launch
create a pivot table the range will be the table name, and not the cell addresses
Pivot Tables work best when you have simple data in rows and columns.
14
When you do so, the create PivotTable
dialog box appears.
• Excel will guess the data range
that you will want; correct it if it is
wrong.
PivotTable Geography
Field
Pivot 2
List
Table
Report
3 4
Drop
Zones 6
5
15
PivotTable Geography
The pivot table will be located here. The size will adjust as it needs to automatically.
1 • NOTE: If you move your mouse out of this area, the PivotTable Field List will disappear. To
get it back, merely left click your mouse within this area again and it will appear.
The fields listed here are your column headers on your original data source.
2 • These fields may be utilized in designing your PivotTable Report.
• You may use a field more than once.
Report Filters:
3 • Similar to a mentally page break. Allows the user to classify the data
4
Column Labels:
• Often created automatically by dragging data fields to the value zone. The user may also
drag data fields to this zone for grouping, etc.
Row Labels:
5
• Most common label
Values:
6 • Wide range of calculations may be performed on the values dragged to this zone.
This table will represent by department, the number of employees per department and their average
salary. We will also change a column header and the number font for the salary column.
16
Figure 1: Building a PivotTable- Part One
17
2
• Select the Dept name with your mouse, left click, and drag it to the row label
1
zone.
• The list our SCOE departments now appear to the left.
2
18
2
• Drag down last name and salary into the Value zone
1
• Last Name
2
o Every employee has a last name. So if we use last name in a value field the
result displayed in the field will merely be the number of last names that
we have.
o Note that the formula used is count because it is a text field.
• Salary
o Excel automatically used the SUM formula.
o The SUM formula needs to be changed to the AVERAGE formula
To change the formula, we will launch the value fields setting dialog box and choose a different
formula.
19
1
Changing a Formula
The value dialog box will appear. Using a left click on your mouse, select the Value Field Settings
2
The value field settings dialog box appears. On the summarized by tab, select the average
3
calculation from the drop down box
20
The result is represented below. 3 Notice that the header now is Average of Salary, rather than Sum
of Salary.
Now we want to change the column headers and the number format.
21
1
Left click on the Count of Last Name column header, B4. Modify the title as you would any title
1
in a normal spreadsheet, in other words, get typing.
Select any cell in the Average of Salary column. Right click on your mouse which launches an
2
option dialog box. Left click on value field settings option which launches the value field setting
dialog box.
In the value field settings dialog box, select the number format button on the bottom left
3
corner.
Within the format cells dialog box, select your desired format
4
22
• Place your mouse anywhere within the
Average of Salary column data.
2
23
Building a PivotTable Report – Part Two
Adding multiple row labels, collapsing and expanding, drill down to data, sorting, &
refreshing
We can expand the detail provided in the pivot table if we would like. Using the table grouped by
departments if the last name is dragged to the row label zone then each department will have the last
name of the employees listed.
24
The results can either be collapsed or expanded by either selecting the collapsed or expanded icon
located on the PivotTable Tools\options tab and within the active fields group. Using the + or – icon
located to the left of each row label will have the same result.
If we want to obtain detail information on our items we can by double left clicking on any calculated
field. For example, if we double click on cell B19, the number of employees in the WES Camp
department, the following appears on a separate tab.
25
Two very useful icons on the PivotTable Tools tab are sort and refresh.
1 2
Sort works exactly the same as the sort on the Data tab. However, if you want to sort the results
1
created in the PivotTable, you must use the icon located on this tab.
If you update your source data, it is imperative to refresh your pivot table results, actually each
2
pivot table created using the same source data.
Pivoting on dates, we will use a default group how to design pivot tables, we will begin with the goal
report, depicted below, and then step through each design component. At the conclusion of Building a
PivotTable Report, all steps will be summarized.
This table will represent by dates, the number of employees per department and their average salary.
We will also change a column header and the number font for the salary column.
26
1
27
• The grouping dialog box appears as
displayed to the left.
28
Tables can also be grouped by ranges. In our previous examples our pivot tables have broken down by
department, the number of employees per department and their average salary. If we wanted to pivot
our data by salary ranges we could with the end result appearing as below.
• To do so:
o select any cell within the row
labels
4
o Select the Layout & Print tab
29
3
Let’s clean up the data a bit by removing the <0 and >0 lines, as well as having the value zero (0)
appear for ranges with no values.
• By choosing the chevron to the right of Row Labels, deselect the <0 and >120000 range.
1
• To display zeros, navigate to PivotTable Tools\options tab and select Options from the
2 PivotTable Group and select options which launches the options dialog box.
3 • Within the Layout & Format tab, insert a zero in the box for the For Empty cells show:
option.
30
3
So far the only grouping we have done has been by the rows. Groups can be done by columns as well. In
all of our first tables, we group on the starting date by grouping, or combining, the individual dates by
month.
Build a pivot table with the departments as the row labels and drop the start dates into the column
labels. The table appears as follows:
To group by the years, navigate your mouse to any date in the pivot table. Right click you mouse so that
the dialog box appears, select group, and select years. Finish by selecting OK. The pivot table appears as
below.
31
The final grouping we will review is by group by categories that are not part of the original table.
Returning to the pivot table where we are pivoting be departments, counting the number of employees
by department, and calculating the average salary, you will recall it appears as below.
32
Building a PivotTable Report – Part Four
User defined groups, adding/removing subtotals
The user may define groups for data that is not included in the original source data.
33
Continue with the group selections until it is completed by cabinet member and appears as below.
34
Selecting the option to display
the subtotals at the bottom of
the group looks like this.
35
• Navigate to the Show values as tab.
• Instead of showing the values as normal, select the down arrow to display
the various options.
You may also make calculations on the pivot table results themselves. For instance, to
calculate the percent of salaries paid by the various departments:
• Drag the salaries once again to the formulas zone.
• Navigate to a cell with the column and right click the mouse to launch the dialog box
• Select value fields settings to launch the dialog box. On the summarize tab, select count.
• Within the value fields settings dialog box now select the show vales as tab.
36
The resulting pivot table
appears to the right.
37
This is a much cleaner
presentation of the data.
To display the labels in tabular form navigate to PivotTable Tools\design tab. Within the layout group select report
layout. 1
2 1
38
The resulting report is easy to
read.
By selecting just 1644 Magnolia as the site, only the selected information will be displayed for those
individuals whose site is 1644 Magnolia.
39
Report Slicers
Report filters are not too exciting; slicers on the other hand are
super cool. By navigating to PivotTable Tools\Sort & Filter group
and select insert slicer.
After selecting Site to filter by, a pop up appears with the list of all
sites. One or many individual sites may be chosen to filter by.
Holding down the shift or Ctrl keys work when selecting multiple
items to filter by.
To remove the slicer, merely select the slicer pane and press the
delete key.
40
Expanding Filter Results to Individual Tabs
Returning to the report filters, there is one feature that gives the cool slicers a run for its money. Simply
put, a single criteria element results may be shown on individual pages, or worksheet tabs.
Utilizing the site report filter that we have before; select PivotTable tools\Options within the PivotTable
group. Then select the chevron to the left of Options and select show report filter pages.
Only one filter can be utilized when filtering to pages. The show report
filters pages pop-up will appear from which you can only select one. Once OK is selected, Excel will do
some quick magic. The tabs below is after the page filter has been applied.
41
1
Select a cell within your data area. From the Home tab, select format as a table from the
1
styles group.
Select the format I want. Choose light in this example.
2
If the table format is no longer desired you may turn off the ‘table formatting’ by navigating to \table
tools\ tools and select the convert to range option.
42
• Report filters is similar to a
page break.