Académique Documents
Professionnel Documents
Culture Documents
Presented by:
C H A P T E R 1 4
441
Schneider_ch14.qxd 7/27/05 1:05 PM Page 442
NOTE In earlier versions of Access, the Pivot Table Wizard was central to creat-
ing pivot tables. With the introduction of views, however, the wizard has lost
much of its value, although it remains a selection in the New Form dialog box.
Similarly, you can continue to use Microsoft Graph to create charts in Access,
but I think you’ll prefer pivot charts when you learn how to build them.
Any table or query can be given a PivotTable view by selecting it from the
View drop-down list (see Figure 14.1). But this is merely the launch point
for creating a pivot table; your work is just beginning. The virgin
PivotTable view in Figure 14.2 can be compared to the Design view that
greets you when you build a new form from scratch—but with one vital dif-
ference. With a form, you build in Design view, but the display is in Form
view. With a pivot table, you build in PivotTable view and display in
PivotTable view. The main building blocks of a pivot table are the fields in
the field list, which you drag and drop onto specific areas of the table.
Schneider_ch14.qxd 7/27/05 1:05 PM Page 443
Figure 14.1 PivotTable and PivotChart are views in a table, form, or query; they are not
separate objects in the Database window.
These areas correspond to the four key elements in a pivot table: row,
column, filter, and totals/detail (see Figure 14.2). These elements, particu-
larly column and detail, work together slightly differently than they do in
an Access table. A simple example is the best way to get a feel for how a
pivot table works.
Figure 14.2 The Order Details table in PivotTable view before any fields have been added.
(The field list has been moved and the table has been resized for a better picture; your
screen will look slightly different.)
3. Open the drop-down list on the View button at the far left of the
toolbar and choose PivotTable View.
Besides all the Orders fields, the field list includes By Week and By
Month selections for fields with the Date/Time data type. (If you
don’t see a field list, choose View, Field List.)
4. Click the + sign next to Order Date by Month.
A full list of measures of time is displayed, including Years and
Quarters.
5. Select Years, and drag and drop it onto Drop Row Fields Here.
In the list, note that Order Date by Month Field and Years Field
now appear in bold.
6. Click the + sign next to 2004 to expand the tree.
Only Qtr3 is displayed because all orders were made in that peri-
od. If orders were made in all quarters, all would be displayed.
7. Click the + sign next to Qtr 3 (see Figure 14.3).
Figure 14.3 You can expand or collapse pivot table items by clicking the + or – buttons.
The months are displayed. You could similarly expand the tree to
display days, hours, minutes, and seconds (if the times had been
entered with such specificity).
8. Click Shipper in the field list. Drag and drop it onto Drop Column
Fields Here.
Schneider_ch14.qxd 7/27/05 1:05 PM Page 445
Note that dropping fields in the Column (or Row) section does not
add values to the detail area. Instead, it gives you the column (or
Row) headings.
Also note that the table displays the ShipperID, the actual ID
stored in the Orders table. If you built a query and included sup-
plier company names on the design grid, you could then display
the names in the pivot table.
TIP When you select fields for columns, they should contain only a few different
values. In other words, the fields can have lots of records, but the data in them
should be highly repetitive, not highly unique. Otherwise, you’ll find yourself
with hundreds or even thousands of columns, and your PivotTable will be difficult
to manage and interpret.
Figure 14.4 Totals can be quickly added to the table using the AutoCalc command on the
shortcut menu.
Schneider_ch14.qxd 7/27/05 1:05 PM Page 446
TIP If the field list disappears, click anywhere in the table. You can also click
View, Field List once (or twice) on the Pivot Table toolbar.
11. Click Overnight? in the field list. Drag and drop it onto Drop
Filter Fields Here.
You can use the Filter area for fields you might want to use as a fil-
ter but don’t want to include on the table itself. For example, you
might want to filter the records by customer state, but you don’t
want any state totals in the table.
12. Click the Overnight? drop-down button.
13. You select and deselect the check boxes to specify the values you
want. The All choice shows all records. You can use the same
method to filter from a row or column field, but you cannot filter
from a totals/data field.
TIP As you can see, the filter tools in a pivot table are limited. One workaround
is to create a filter with your usual methods (such as Filter by Selection) in
Datasheet or Form view and then switch to PivotTable view.
14. Deselect Yes to show only those records sent by regular freight.
Click OK.
The values in the pivot chart are adjusted accordingly.
15. Click the drop-down list next to Shipper (see Figure 14.5).
Auto Filter
Show As
Hide Details
Show Details
Field List
Figure 14.5 You can filter records using row, column, or filter fields.
Schneider_ch14.qxd 7/27/05 1:05 PM Page 447
You can filter the Shipper records by similarly selecting and dese-
lecting the records you want.
16. Click Cancel. Close the table. Click Yes to save the layout changes.
Occasionally, all the fields you need for a pivot table will be in a single
table. But it’s more likely that you will want to use fields from several
tables. Thus, you will usually want to begin a pivot table by creating a
query. In the following example, you create a query and then use it to learn
more about the various features and functions of pivot tables.
Suppose that as the Nifty Lions sales manager, you want to get a sense
of what kind of merchandise is selling best in each state, as well as which
of your suppliers are providing this merchandise. To do this analysis, you
need to know the category (for type of merchandise), the customer’s state,
the merchandise in each order, and who supplies which product. Table
14.1 shows the fields you need.
Figure 14.6 The Orders and Order Details fields have been added only to provide a
join between the Customers and Merchandise fields.
Figure 14.7 A pivot table makes it easy to quickly add totals to the grid.
8. Click Company Name. Drag it all the way to the left. When you see
the heavy blue line, drop it to the left of CustState.
Now you can see the merchandise ordered broken down by sup-
plier and further broken down by customer state.
9. Click Company Name on the pivot table (to the left of
CustState). Drag it to the left of CategoryName. When you see
the heavy blue line (see Figure 14.8), drop it.
This gives you counts broken down first by supplier and then by
category.
10. Save your query and close it.
Company
Name field
Dropped Here
Figure 14.8 One of the many advantages of pivot tables is that you can easily switch fields
to a different axis. Here the Company Name field is just about to be dropped to the left of
Category Name.
Schneider_ch14.qxd 7/27/05 1:05 PM Page 451
TIP Because pivot tables are so flexible, it is tempting to throw lots of fields into
the query, just in case you want to include another element. But I suggest that
you decide beforehand what information you want the pivot table to show and
use only the data you need for each query. You can always create another
query or add fields to an existing one, if you need to.
Figure 14.10 In the field list, you can use the Add To button to place fields in the various
sections of the pivot table.
TIP To remove a field from the pivot table, right-click it and choose Remove.
Q&A
Q: I’ve been using pivot tables a bit, and there’s one thing I don’t get. A
lot of the time I get a bunch of empty columns that say No Details (see
Figure 14.11). Why is this happening? How do I stop it? Do I want to
stop it?
A: I was afraid you were going to ask me that. Let me try to explain
what’s going on.
In the drop-down list next to the Add To button you’ll find a Detail Area
selection (which I used in the previous example) and a Data Area selection
(which I didn’t). When you choose Detail Area, you add the actual values
to the table. When you choose Data Area, you add only totals, not the
Pivot tables come with an array of features that either enhance your ana-
lytical power or simply make life easier and more pleasant. On the mun-
dane side, you can change fonts and supply captions. On the much more
interesting analytical side, you can create group items and filter for top (or
bottom) values. Most of the fine-tuning is performed in the Properties dia-
log box, which is available from the context (shortcut or right-click) menus.
The properties in the dialog box, as with those in the property sheet in a
form, depend entirely on which element of the table you select.
Subtotals
Filter symbol
Figure 14.13 The Top/Bottom Values command hides all orders except those with the
highest freight cost.
Grouping Records
Sometimes you want to group records by intervals. For example, you might
want to group the records by OrderID number.
7. Close the Properties dialog box. The OrderIDs are now grouped
in units of five (see Figure 14.14).
8. Close the query and save your changes.
On the other hand, for the most part, there’s no need to bother with an
underlying pivot table if your only objective is to create a pivot chart. You
can create the chart directly in PivotChart view. Moreover, when you cre-
ate a pivot chart, you can choose among numerous chart types, each of
which presents data graphically in its own way. So when your objective is a
pivot chart, I advise doing all your work in PivotChart view and ignoring
PivotTable view entirely.
NOTE This general rule has some exceptions. If you want to display aggregate
functions besides Sum and Count, you’ll need to create them first in PivotTable
view. They will then be available in the pivot chart’s field list, and you can add
them to the chart.
Figure 14.15 shows a pivot chart that contains no fields. As with pivot
tables, you drag and drop fields from the field list onto the chart. Where
exactly you drop the fields is of utmost importance.
Figure 14.15 A blank pivot chart. The scale at the left is purely a template view and will
change to reflect the values in your chart.
Schneider_ch14.qxd 7/27/05 1:06 PM Page 459
1. In the Database window, click Queries and click New. In the New
Query dialog box, click Design View and click OK.
Schneider_ch14.qxd 7/27/05 1:06 PM Page 460
2. In the Show Table dialog box, click tblCategories, press Ctrl, and
click tblMerchandise and tblSuppliers. Click Add to add the three
field lists to the design grid. Close the Show Table dialog box.
3. In the Categories field list, double-click CategoryName. In the
Merchandise field list, double-click MerchName, UnitsInStock,
and UnitsOnOrder. In the Suppliers field list, double-click
SuppCompanyName.
4. Save the query as qryMerchandiseUnits.
5. Click View to see and review your records in Datasheet view.
6. Click the View drop-down arrow and choose PivotChart view.
7. Click Category Name in the field list and drop it onto Drop Series
Fields Here (if you can’t find Drop Series Field Here, refer to
Figure 14.15 for its location).
Because you have only five types of product, this will work nicely
as a series. You’ll be able to use the legend to quickly distinguish
one category from the next.
8. Click Company Name and drop it onto Drop Category Fields
Here.
Let’s think about the relationship between suppliers and products
for a moment. Each supplier sells several products, and each prod-
uct has only one supplier. If you want to see which products are
supplied by which supplier, it’s best to put suppliers first (on the
outside) and products second (on the inside).
9. Click Product Name and, in the Drop Category Fields Here area,
drop it to the right of Company Name.
10. Click Units in Stock and drop it onto Drop Data Fields Here.
Units in stock is the data you want to measure. The scale at the left
tells you how many units are in stock for each product.
Take a look at the chart. There are some problems. First, where’s
the legend that tells the product type (jewelry, novelty, and so on)?
You can easily display it.
11. On the PivotChart toolbar, click Show Legend (see Figure 14.16).
The next big problem is that listing suppliers and products along
the x-axis makes them difficult to read.
Perhaps if you used another chart type, the chart could be read
more easily. Instead of a column chart, use a bar chart that will
measure the units along the x-axis instead of the y-axis.
Schneider_ch14.qxd 7/27/05 1:06 PM Page 461
Show Legend
Figure 14.16 A pivot chart built from a query. It has the data you need, but its
presentation could be improved.
Figure 14.17 In the Properties dialog box, you can choose another chart type. Click the
type of chart in the left column, and choose a chart on the right.
Schneider_ch14.qxd 7/27/05 1:06 PM Page 462
Figure 14.18 The bar chart shows the number of units in stock for each product by
supplier, as well as the product category. It still needs some work, however: You can add
axis titles, eliminate the decimal places on the scale, and more by using the Properties
dialog boxes described in the next section.
Suppose you also wanted to show the Units On Order for each prod-
uct. Let’s add it to the chart:
1. Click Units On Order in the field list. Drag and drop it to the
right of Sum of Units in Stock.
2. This chart gives you the data. But on smaller screens, it will be dif-
ficult to read because the parallel Units In Stock and Units On
Order bars are difficult to distinguish. Let’s choose another chart
type.
3. Right-click any empty area on the chart and choose Chart Type.
On the Type tab, click Bar. Click the second sample in the first row
(see Figure 14.19). Close the Properties dialog box.
4. You can now see both units in stock and units on order. The total
length of each bar shows the sum of units in stock and units on
order, an additional and useful piece of information. The legend is
now a bit complicated, with 10 categories, but it can still be deci-
phered.
5. Save your changes and close the query.
Schneider_ch14.qxd 7/27/05 1:06 PM Page 463
Figure 14.19 This bar chart includes both data fields on the same bar.
Figure 14.20 You might want multiple charts to segregate presentations of different data
elements.
Chart Properties
As with pivot tables, you can set a host of properties for each of the many
elements in the chart. Editing chart properties can get confusing because
there are so many choices and so many parts. Choosing the correct ele-
ment is crucial—the properties you edit depend completely on the ele-
ment chosen. But finding the right place to click is a task unto itself. Look
at the element name in the Select box in the General tab of the Properties
dialog box to make certain you’ve chosen the one you need.
One possible (but by no means foolproof) solution is to select the ele-
ment you want from the General tab in the Properties dialog box. Even a
simple chart has a host of elements, however, and figuring out which ele-
ment is which from their names can be difficult (see Figure 14.21).
Schneider_ch14.qxd 7/27/05 1:06 PM Page 465
Table 14.2 shows you how to edit several key items in the various prop-
erties dialog boxes.
Show the field Chart Workspace Show/Hide Select the Field List
list by default
Show the scale in a Value Axis Format Open the Number
different format drop-down list
(e.g., percent or and select a format
currency)
Change the units on Value Axis Scale Edit Custom Major
the scale Unit
(continues)
Schneider_ch14.qxd 7/27/05 1:06 PM Page 466
Conclusion
In this chapter, you learned the basics of pivot tables and pivot charts.
Hopefully the discussion was useful, but I’m certain that for some readers
it was simplistic. The examples I used didn’t include any calculated expres-
sions, which are often integral to data analyses. For example, extensions of
quantity and unit price (such as 7 units @ $3 = $21) would be han-
dled by a calculated expression.
An excellent place to learn about the use of calculated expressions in
pivot tables/charts is a Microsoft Support WebCast on the topic; in fact, it’s
a good introduction (or, at this point, review) of the entire area. The web-
cast is for Access 2002, but nearly all of it is still applicable for Access 2003.
You can find it as Microsoft Knowledge Base Article 324695. Both the full
webcast (sound and PowerPoint presentation) and the printed transcript
are offered.
Schneider_ch14.qxd 7/27/05 1:06 PM Page 467
Conclusion 467
CASE EXAMPLE
In Chapter 11, “Forms/Subforms,” you learned how to create a form/subform.
The subforms you created were in Datasheet view, but they could have also
been displayed in PivotTable view or PivotChart view. As you move from record
to record in the main form, the subform’s pivot table or pivot chart changes to
correspond to the main record.
In the following example, you’ll use the Form Wizard to create a form with
a subform. You’ll then design the pivot chart.
5. Click Next. View your data by tblOrders and Form with Subform(s).
Click Next.
6. Choose PivotChart for the layout of the subform. Click Next.
7. Select the Standard style and click Next.
8. Name the form frmOrders and the subform frmPivotOrderDetails
subform.
9. Click Finish.
Access creates your form, with the subform in PivotChart view (see
Figure 14.22). Let’s get to work on the subform.
Figure 14.22 The new form/subform in Form view. You still have much work to do on the
pivot chart.
Schneider_ch14.qxd 7/27/05 1:06 PM Page 468
Pivot Chart
label
Pivot Chart
Be sure to select the entire chart, not just the data area. If you want to
make sure you’ve selected the entire chart, choose View, Properties. In
Select on the General tab, Chart Workspace should be selected.
Conclusion 469
9. Click Selling Price and drop it onto Drop Data Fields Here.
10. Click MerchName and drop it onto Drop Category Fields Here.
11. Right-click in an empty space in the chart and choose Properties. If nec-
essary, open the Select box on the General tab and choose Chart
Workspace.
12. On the General tab, click the Add Legend icon (see Figure 14.25).
Schneider_ch14.qxd 7/27/05 1:06 PM Page 470
Figure 14.25 The Properties dialog box for the Chart Workspace and the Add Legend icon.
13. Right-click Axis Title on the x-axis. If the Properties dialog box isn’t still
open, choose Properties. Click the Format tab. Edit the caption to
Merchandise.
14. With the Properties dialog box still open, click Axis Title on the y-axis.
Edit the caption to Price.
15. Close the property sheet. Click in any empty space to deselect the
y-axis title.
16. Edit the Record Selector box to 16 (see Figure 14.26).
Schneider_ch14.qxd 7/27/05 1:06 PM Page 471
Conclusion 471
Figure 14.26 The final pivot chart, with captions for the axis titles.
The pivot chart tells you that OrderID 16 included one screen saver at
a price a little above $6 and three small stuffed lions at a price a little
above $11.
This chapter is excerpted from the book titled, Hands-On Microsoft Access: A Practical Guide
to Improving Your Access Skills, authored by Bob Schneider, published by Addison Wesley
Professional in August 2005. ISBN 0321245458. Copyright 2006. Reprinted with permission. All
rights reserved.