1. Trang chủ
  2. » Công Nghệ Thông Tin

beginning microsoft excel 2010 phần 8 pps

40 226 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 40
Dung lượng 11,63 MB

Nội dung

CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 266 —that list of family expenses. Turn this database into a table, as we saw in Chapter 6, and you could, for example, filter Newspaper and/or Telephone expenses and calculate their respective contributions to the budget—and an Advanced Filter would enable you to save those data to another location on the worksheet. You could also gener ate a count of the number of Newspaper or Telephone payments, by clicking on Count Number in the Expenses cell in the table’s Total row. But if you need a more comprehensive breakout—say you want to see Newspaper costs by each month, in which three variables, or fields, are considered at the same time—Expense, Date, and Sum— then the task becomes more challenging. My professional recommendation: you need a PivotTable. Indeed, the revised budget portrait we presented in Chapter 1 (Figure 8–2): Figure 8–2. The budget data broken out by category and month was engineered by a PivotTable. Data from two fields, Expense and Date, form a set of borders around the actual expense data, which are then broken out into individual totals at the intersections of each Expense and each Date, in this case defined in monthly units (of course some of the intersections are blank, simply because that type of expense wasn’t incurred that particular month). It’s this sort of thing that a PivotTable can do with ease, and the sort of thing that a table can’t. This object used to be called a crosstab—a kind of matrix in which data were organized by one variable displayed horizontally (in the above case, by Date), and another displayed vertically (Expense). PivotTables are latter-day, electronic descendants of the crosstab, and once you acquire a basic understanding of how they work, you can cook one up in about four seconds—at the same speed as an Excel chart. It’s true that PivotTables are viewed by some users as a rather forbidding and daunting object-and I’ll allow that when I first set eyes on a PivotTable, in pre-millennium New York, I had no clue what they were about. By the second look, however, PivotTables began to make considerably more sense—and if you understand what’s going on in the screen shot above, and doubtless you do-you’re on your way. Of course we can’t tell you everything about PivotTables in this chapter—whole books have been devoted to just this topic (two by Apress, by the way). But we are going to describe the PivotTable essentials-and then some—so you’ll be able to do quite a bit of productive work with them. CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 267 What’s in a Name? PivotTables are so named because they enable the user to move, or pivot, table data to various positions on an area called a pivot grid (you’ll see it soon), thus breaking out the data in a wide range of changeable ways. Thus in the above case, the Expense field data occupies what’s called the Row Labels area, the actual budget expenses are assigned to the Value area, and the Dates here are installed in the Column Labels area. Now that’s a rather abstract description, but consider this illustration, an excerpt from a table of sales data, adapted from one of Microsoft’s sample files, one we’re going to work with in this chapter (Figure 8–3): Figure 8–3. Table data—about to turn into PivotTable data I say “excerpt” because the table—which for the purposes of this chapter we’re going to call the PivotTable’s source data-comprises one header row and 799 records (though again, the number of records with which you work is largely irrelevant-the PivotTable concepts are the same). It’s a pretty straightforward collection of information, recording each sale by each salesperson, date, country of sale, order number, and sales amount. Tossing these data into a PivotTable, I could do something like this (Figure 8–4): CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 268 Figure 8–4. Sales data compiled by a PivotTable—by country and salesperson Here the sales data are broken out by Salesperson and Country. Thus Davolio did $182,500.09 worth of business in the USA, and none in the UK (and note the original table data are formatted as currency, but not here; the PivotTable awaits your decision on this). But I could also redesign the table (the PivotTable that is) to take on this appearance instead (Figure 8–5): Figure 8–5. Same data, different arrangement—the salesperson names are now running across a set of columns Same exact information—but here I’ve pivoted the table, so that the Row Labels area shows the Country data, and the Column Labels area displays the Salesperson. I’ve given the data a different, almost perpendicular look. Which look you prefer is a presentational decision, and PivotTables make these and many other such options available. Note as well that data from only three of the original table’s five fields have been invoked in this PivotTable—Country, Salesperson, and Order Amount (see the Sum of Order Amount caption in the PivotTable’s upper-left corner); that tells us that you can apply the original table fields selectively to a PivotTable, and leave out the ones that don’t currently interest you. But nothing in PivotTables is forever; you can start over again and introduce whichever fields you like, as your needs warrant. But all this raises the obvious question: How do you actually start doing all this? I thought you’d never ask. So let’s go. Constructing a PivotTable: Let’s Go To give PivotTables a try, download the SampleSalespersonReport workbook from our download page at apress.com. Let’s say you want to construct a first PivotTable, or pivot report as it’s officially termed, which simply breaks out all sales in dollars by Salesperson. That is, we want to wind up with this report (Figure 8–6): CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 269 Figure 8–6. For starters: A basic PivotTable Inserting the Table To begin the process, click anywhere in the original table data (on the Source Data worksheet). Then click the Insert tab  PivotTable (in the Tables button group(  PivotTable  and OK (we’re accepting all the defaults in the dialog box). You’ll see (Figure 8–7): Figure 8–7. A PivotTable grid—where to till your fields Look to the right of your screen, and you’ll see (Figure 8–8): CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 270 Figure 8–8. The PivotTable Field List: where you decide what goes where Note as well that when you click anywhere in the PivotTable area, even if it’s blank as per the above screen shot, a PivotTable Tools tab appears onscreen, complete with an array of buttons to help you construct and reconstruct the table on which you’re working (Figure 8–9): Figure 8–9. The PivotTable ribbon CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 271 Needless to say, these screenshots need to be explained. The first shot (Figure 8–8) captures the areas, all currently empty, in which the various data from the data source (that is, the original table) are to be positioned, or dropped. We’ve already identified most of these: Row Labels, Column Labels, and Values (the fourth, the Report Filter, streaming across the upper edge of the screenshot, remains to be discussed). The second screen shot identifies what’s called the PivotTable Field List, whose upper half simply lists the names of the data source fields. Setting Up the PivotTable Now remember that we want to compile a sales-in-dollars-by-salesperson pivot report. Here goes: 1. To start, click the Salesperson check box on the PivotTable Field List. That means we want to see information from that field, which consists simply of the names of the salespersons recorded each time they register a sale: You’ll see (Figure 8–10): Figure 8–10. The Salespersons. Note that each is listed only once. This introduces an important point, one of those PivotTables have-to-knows. Note that all the salesperson names are listed in the row area as a result of that click, but each is listed only once. Remember our source data contains 799 records, but nevertheless when those data are installed in the Row Label area, each salesperson is listed once, that is, uniquely. After all, we want to aggregate the sales data by salesperson, so it stands to reason that each name is enumerated once, in order to summarize and report their total sales. The general principle here is: Any field data that is placed in the Row Label area lists its distinct entries once, and only once. We see that our sales force comprises nine salespersons, and no matter how many sales any one of them records, her name will be listed in the Row Label area once (we’ll need to qualify this point a bit later, but that’s the essential idea). Note in addition that when we clicked on the Salesperson check box, those data were sent directly to the Row Label area. That was Excel’s decision, not ours, because Excel assumes that this kind of data—which is textual—is the kind that is typically assigned to the Row area. But as we’ll see, you can place any source data field in any of the PivotTable areas. 2. Next, click the check box next to the Order Amount field. You’ll see (Figure 8– 11): CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 272 Figure 8–11. Finito—your first PivotTable Don’t look now, but we’re done. Clicking the Order Amount check box did these things: • It delivered the data in that field-the sales data in dollars—to the Values area. • Those data were in turn aggregated by each name in the Row Label area, which controls the process by dictating how the data are to be aggregated. Note also that by default, the salespersons are sorted in A-Z sequence. So there’s your first pivot report, and whether you realize it or not, we’ve already encountered and worked with three of the most important principles of the report-making process. To summarize these: • The data from any field placed in the Row Label area are always listed, and listed once each (again, we’ll need to modify this slightly later). Our nine salespersons are thus each listed once in the Row Label area, irrespective of the number of sales they achieve. Let any salesperson record 1 or 50,000 sales; she or he will be listed only once. • Any data placed in the Values Label area is subject to some kind of mathematical operation. In our case the Order Amount data was added, and keyed to or broken out by each salesperson. • Any source data field can be placed in any PivotTable area. If it’s placed in the Row Label area, that field’s contents will be listed uniquely. If it’s placed in the Values area, the field’s contents will submit to some kind of mathematical operation. Keep these principles in mind; they should become clearer as we proceed. Note in addition that buttons representing the two fields we’ve selected thus far—Salesperson and Order Amount-are also slotted into their respective places in the lower half of the Field List (Figure 8–12): CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 273 Figure 8–12. Pivoting the Report: Table fields currently in use Now click the drop-down arrow on the Salesperson button. You’ll see (Figure 8–13): Figure 8–13. Rearranging the PivotTable—we’re about to pivot it CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 274 Click Move to Column Labels. This is what happens (Figure 8–14): Figure 8–14. The same data, now running horizontally We’ve pivoted the repor t. The Salesperson names now occupy a succession of columns stretching horizontally across the report, framing a new way for looking at precisely the same data. (Note: You can also move the buttons from one area to another by clicking on a button and dragging it into a different area. You’ll also gradually discover, to your delight or befuddlement, that PivotTables offer many ways for doing the same things.) And we’re also learning that the Column Labels area is really a horizontal version of Row Labels—as with that latter area, any source data assigned to the Column Label space will be listed uniquely. Updating the Pivot Report There’s something else to keep in mind, this time about the source data that contributes to a pivot report. If you add new records to the source data, or if even if you change any of the data in an existing record, you need to refresh the pivot report. Unlike standard Excel formulas, PivotTables won’t automatically recalculate when the data contributing to them is changed. To refresh a PivotTable, click PivotTable Tools  Refresh (keyboard equivalent: Alt+F5). To demonstrate, let’s add a record to our source data. Return to the source data, and in Row 801 enter these data: UK, Buchanan, 2/5/10, 11111, $567.00. Then click back onto the pivot report and click the Refresh command. You’ll see (Figure 8–15): Figure 8–15. The pause that refreshes: updating, or refreshing, the PivotTable with a new record—a new Buchanan sale Note that Buchanan’s sales total has bumped up to 69359.35, reflecting the additional $567.00 sale. Way to go, Buchanan. The Refresh All option, revealed by the drop-down menu by Refresh, also refreshes source data that may be drawn from an external source, such as a Web site or an Access database (You’d click Use an external data source in the Create PivotTable dialog box to connect to such a source.). Note as well that if you build several different pivot reports, simultaneously drawing on the same source data—and you can—all will be refreshed. Changing the Calculation Next point. Suppose instead of having the pivot report calculate the total sales for each salesperson— that is the default calculation—you want to determine the average sale in dollars each salesperson has executed. To do this (among other ways), first click anywhere in the pivot report data label area, (where the sales numbers appear), then click PivotTable Tools  Options  Summarize Values By  Average (you’ll see this command on the resulting drop-down menu) (Figure 8–16): CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 275 Figure 8–16. No mean feat: Changing the mathematical operation of a field to Average The salesperson data now display average sales by salesperson. Click the Summarize Values By drop-down arrow and you’ll see that you can also carry out these operations: Count, Max, Min, and Product (which in our case would multiply each salesperson’s sales all together, yielding a rather gigantic total). Clicking More Options gives a few additional possibilities, including Standard Deviation. (By the way, we’ll get to how to format these data in a little while.) Comparing the Data And here’s another cool way to characterize your data. By clicking anywhere in the pivot report and then clicking PivotTable Tools  Options tab  Calculations group  the Show Values As drop-down arrow, you’ll see (Figure 8–17): Figure 8–17. The Show Values As drop-down menu: more ways to compare the numbers [...]... report (Figure 8 40): Figure 8 40 Country sales, by salespersons Or, by exchanging the order of Salesperson and Country, this (Figure 8 41): Figure 8 41 Salespersons, by country 289 CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS That’s not bad, but the recurring UKs and USAs are a touch untidy; and there’s a neater approach Drag Country into the Report Filter area You’ll see (Figure 8 42): Figure 8 42 Putting... say below Country (Figure 8 44): 290 CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS Figure 8 44 Report Filtering by two fields You’ll wind up with this (Figure 8 45): Figure 8 45 This double Report Filter can be tweaked to bring about this result… As a result, you’ll be able to conduct a double filter, by selecting a particular order ID as well as a country (Figure 8 46): Figure 8 46 …where the data are showing... if you’ve designed this basic pivot report (Figure 8 31): Figure 8 31 We’ve seen this report before, but… where the Order Amount field is summed in the Values area, you can drag that field from the PivotTable Field List into the Values area a second time, yielding this, for starters (Figure 8 32): 284 CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS Figure 8 32 Here we’ve added the same field twice—to the Values... the Row Labels area and click the Filter Top 10…, you’ll see (Figure 8 38) : Figure 8 38 The Top 10 dialog box Now because we have only nine salespersons, a Top 10 list just won’t do If you either type 5 to replace the number 10 or click the down arrow until you arrive at that number and click OK, you’ll see (Figure 8 39): Figure 8 39 Quite a quintet-the top five salespersons, by dollars generated Now... (Figure 8 22): Figure 8 22 Economic collapse, of sorts—collapsing the UK sales data Click what is now the plus sign and the Salesperson data reappear You can also execute this command by clicking in the now-collapsed UK row and then clicking PivotTable Tools Options tab Active Field, and clicking the accompanying plus and/or minus signs (Figure 8 23): 2 78 CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS Figure 8 23... entry in the Salesperson Row Label area (but not UK or USA), and click Field Settings on the shortcut menu You’ll see (Figure 8 26): 280 CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS Figure 8 26 The Field Settings dialog box Click None OK, yielding this view (Figure 8 27): Figure 8 27 Note the missing Salespeson subtotals (You can also click PivotTable Tools Design tab Subtotals Do Not Show Subtotals.) Therethat’s... least in part (Figure 8 56): Figure 8 56 Listed numbers: Each transaction sum, arrayed in the row label area True to Row Label form, the data here are merely listed uniquely (and that means if two sales came to say, $50 each, that number would be listed only once) Now, if I click the Group Selection command, I’ll see (Figure 8 57): 2 98 CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS Figure 8 57 Grouping this...CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS Here you’re presented with a wide assortment of options for describing your data comparatively, for example, how each salesperson’s sales total ranks If I click Rank Largest to Smallest I’ll see (Figure 8 18) : Figure 8 18 Assigning a ranking order to the salespersons by their sales Click OK (this... salespersons has been filtered (Figure 8 48) : Check Select Figure 8 48 A Report Filter for two salespersons—but which two? The problem here is that the entry alongside Salesperson—Multiple Items—is not very revealing You can’t tell exactly which salespersons have been included by the filter, and you may need to be able to present that information on screen What to do? 292 CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS... Group button group You’ll call up this dialog box (Figure 8 54): Figure 8 54 Here’s where you select time-based grouping interval 5 Note the various grouping options, which obviously apply to date data We’ll leave the default Months selection in place and click OK You’ll see (Figure 8 55): 297 CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS Figure 8 55 Aggregating by months discloses important patterns in . (Figure 8 7): Figure 8 7. A PivotTable grid—where to till your fields Look to the right of your screen, and you’ll see (Figure 8 8) : CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 270 Figure 8 8. . You’ll see (Figure 8 26): CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 281 Figure 8 26. The Field Settings dialog box Click None  OK, yielding this view (Figure 8 27): Figure 8 27. Note the. (Figure 8 24): Figure 8 24. Movin’ on up—reversing the position of the fields in the row label area Click Move U p. You’ll see (Figure 8 25): CHAPTER 8 ■ PIVOTTABLES AND PIVOT CHARTS 280

Ngày đăng: 14/08/2014, 09:20