Pivot Table Data Crunching for Microsoft Office Excel 2007 [1 ed.] 9780789736017, 0789736012

This book consolidates all the best functionality of pivot tables into one guide that provides you with a meaningful tut

310 87 9MB

English Pages 353 Year 2007

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

Pivot Table Data Crunching for Microsoft Office Excel 2007 [1 ed.]
 9780789736017, 0789736012

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

C o n t e n t s a t a G l a n c e

?usinesssolutions Pivot Table Data Crunching for Microsoft Office Excel 2007 ®

®

Bill Jelen Michael Alexander

800 E. 96th Street Indianapolis, Indiana 46240

1 2 3 4 5 6 7 8 9 10 11 12 A

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 Pivot Table Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 Creating a Basic Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21 Customizing a Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45 Controlling the Way You View Your Pivot Data . . . . . . . . . . . . . . . . . .83 Performing Calculations Within Your Pivot Tables . . . . . . . . . . . . . .117 Using Pivot Charts and Other Visualizations . . . . . . . . . . . . . . . . . . .141 Analyzing Disparate Data Sources with Pivot Tables . . . . . . . . . . .167 Sharing Pivot Tables with Others . . . . . . . . . . . . . . . . . . . . . . . . . . . .189 Working with and Analyzing OLAP Data . . . . . . . . . . . . . . . . . . . . . .201 Enhancing Your Pivot Table Reports with Macros . . . . . . . . . . . . . .215 Using VBA to Create Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . .231 Common Pivot Table Issues and Questions . . . . . . . . . . . . . . . . . . . .291 Finding Pivot Table Commands on the Ribbon . . . . . . . . . . . . . . . .315

Pivot Table Data Crunching for Microsoft® Office Excel® 2007 Copyright © 2007 by Pearson Education, Inc. All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-7897-3601-2 Library of Congress Cataloging-in-Publication data is on file. Printed in the United States of America First Printing: December 2006 09 08 07 06 4 3 2 1 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Que Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Microsoft is a registered trademark of Microsoft Corporation. Excel is a registered trademark of Microsoft Corporation. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book. Bulk Sales Que Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact U.S. Corporate and Government Sales 1-800-382-3419 [email protected] For sales outside of the U.S., please contact International Sales [email protected]

Associate Publisher Greg Wiegand

Acquisitions Editor Loretta Yates

Development Editor Kevin Howard

Managing Editor Gina Kanouse

Project Editor Andy Beaster

Copy Editor Chuck Hutchinson

Indexer Erika Millen

Proofreader Heather Arle

Technical Editor Juan Pablo González

Team Coordinator Cindy Teeters

Interior Designer Anne Jones

Cover Designer Anne Jones

Compositor Juli Cook

Table of Contents Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 What You Will Learn from This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1

What Is New in Excel 2007’s Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Skills Required to Use This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Case Study: Life Before Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 The Invention of the Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 Case Study: Life After Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 Sample Files Used in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9 Conventions Used in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9 Referring to Ribbon Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9 Special Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10

1 Pivot Table Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 What Is a Pivot Table? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 Why Should You Use a Pivot Table? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 When Should You Use a Pivot Table? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 The Anatomy of a Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 Values Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 Row Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15 Column Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15 Report Filter Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16 Pivot Tables Behind the Scenes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16 Limitations of Pivot Table Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 A Word About Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19

2 Creating a Basic Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21 Preparing Your Data for Pivot Table Reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21 Ensure Your Data Is in a Tabular Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22 Avoid Storing Data in Section Headings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22 Avoid Repeating Groups as Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23 Eliminate Gaps and Blank Cells in Your Data Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23 Apply Appropriate Type Formatting to Your Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 Summary of Good Data Source Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 Case Study: Cleaning Up Data for Pivot Table Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25 Creating a Basic Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26 Adding Fields to the Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29 Adding Layers to Your Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32 Rearranging Your Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32 Creating a Report Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33 Case Study: Analyzing Activity by Market . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35

iv

Pivot Table Data Crunching for Microsoft Office Excel 2007 Keeping Up with Changes in Your Data Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39 Changes Have Been Made to Your Existing Data Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40 Your Data Source’s Range Has Been Expanded with the Addition of Rows or Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40 Sharing the Pivot Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41 Side Effects of Sharing a Pivot Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41 Saving Time with New Pivot Table Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42 Deferring Layout Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42 Starting Over with One Click . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42 Relocating Your Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44

3 Customizing a Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45 Making Common Cosmetic Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46 Applying a Table Style to Restore Gridlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47 Changing the Number Format to Add Thousands Separators . . . . . . . . . . . . . . . . . . . . . . . . . . . .47 Replacing Blanks with Zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49 Changing a Field Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51 Making Layout Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52 Using the New Compact Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52 Using the Outline Form Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54 Using the Traditional Tabular Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54 Case Study: Converting a Pivot Table to Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56 Controlling Blank Lines, Grand Totals, Subtotals, and Other Settings . . . . . . . . . . . . . . . . . . . . . .59 Customizing the Pivot Table Appearance with Styles and Themes . . . . . . . . . . . . . . . . . . . . . . . . . . .61 Customizing a Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62 Choosing a Default Style for Future Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .64 Modifying Styles with Document Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .64 Changing Summary Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65 Understanding Why One Blank Cell Causes a Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65 Using Functions Other Than Count or Sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66 Adding and Removing Subtotals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68 Suppress Subtotals When You Have Many Row Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68 Adding Multiple Subtotals for One Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69 Using Running Total Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70 Display Change from Year to Year with Difference From . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71 Compare One Year to a Prior Year with % Difference From . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72 Track YTD Numbers with Running Total In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72 Determine How Much Each Line of Business Contributes to the Total . . . . . . . . . . . . . . . . . . . . .72 Create Seasonality Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73 Measure Percentage for Two Fields with % of Total . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73 Compare One Line to Another Line Using % Of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75 Track Relative Importance with the Index Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75

Contents

Case Study: Producing Revenue by Line of Business Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81

4 Controlling the Way You View Your Pivot Data . . . . . . . . . . . . . . . . . . . . . . . . . . .83 Grouping Pivot Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83 Grouping Date Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .84 Including Years When Grouping by Months . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86 Grouping Date Fields by Week . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86 Grouping Two Date Fields in One Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 Case Study: Creating an Order Lead-Time Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 Grouping Numeric Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89 Case Study: Grouping Text Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90 Ungrouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92 Looking at the PivotTable Field List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93 Docking and Undocking the PivotTable Field List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93 Rearranging the PivotTable Field List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93 Using the Areas Section Drop-Downs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .94 Using the Fields Drop-Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .94 Sorting in a Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96 Sorting Using the Sort Icons on the Options Ribbon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96 Sorting Using the Field List Hidden Drop-Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98 Understanding the Effect of Layout Changes on AutoSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100 Using a Manual Sort Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100 Using a Custom List for Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101 Filtering the Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .102 Adding Fields to the Report Filter Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103 Choosing One Item from a Report Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104 Choosing Multiple Items from a Report Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104 Quickly Selecting or Clearing All Items from a Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106 Using the Field List Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106 Using Label Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .108 Using Date Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109 Using Value Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111 Case Study: Creating a Top 10 Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116

5 Performing Calculations Within Your Pivot Tables . . . . . . . . . . . . . . . . . . . . . . .117 Introducing Calculated Fields and Calculated Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117 Method 1: Manually Add the Calculated Field to Your Data Source . . . . . . . . . . . . . . . . . . . . . .118 Method 2: Use a Formula Outside Your Pivot Table to Create the Calculated Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .118 Method 3: Insert a Calculated Field Directly into Your Pivot Table . . . . . . . . . . . . . . . . . . . . . . .119 Creating Your First Calculated Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .121 Case Study: Summarizing Next Year’s Forecast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124

v

vi

Pivot Table Data Crunching for Microsoft Office Excel 2007

Creating Your First Calculated Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129 Understanding Rules and Shortcomings of Pivot Table Calculations . . . . . . . . . . . . . . . . . . . . . . . .133 Remembering the Order of Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134 Using Cell References and Named Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135 Using Worksheet Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135 Using Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135 Referencing Totals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135 Rules Specific to Calculated Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135 Rules Specific to Calculated Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136 Managing and Maintaining Your Pivot Table Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137 Editing and Deleting Your Pivot Table Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137 Changing the Solve Order of Your Calculated Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .138 Documenting Your Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .139 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140

6 Using Pivot Charts and Other Visualizations . . . . . . . . . . . . . . . . . . . . . . . . . . . .141 What Is a Pivot Chart…Really? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141 Creating Your First Pivot Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .142 Keeping Pivot Chart Rules in Mind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145 Changes in the Underlying Pivot Table Affect Your Pivot Chart . . . . . . . . . . . . . . . . . . . . . . . . .145 The Placement of Data Fields in Your Pivot Table May Not Be Best Suited for Your Pivot Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .145 A Few Formatting Limitations Still Exist in Excel 2007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146 Case Study: Creating a Report Showing Invoice Frequency and Revenue Distribution by Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .148 Examining Alternatives to Using Pivot Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .153 Method 1:Turn Your Pivot Table into Hard Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .153 Method 2: Delete the Underlying Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .154 Method 3: Distribute a Picture of the Pivot Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .154 Method 4: Use Cells Linked Back to the Pivot Table as the Source Data for Your Chart . . . . . .154 Using Conditional Formatting with Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .157 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .166

7 Analyzing Disparate Data Sources with Pivot Tables . . . . . . . . . . . . . . . . . . . . .167 Using Multiple Consolidation Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168 Analyzing the Anatomy of a Multiple Consolidation Range Pivot Table . . . . . . . . . . . . . . . . . . . . .174 The Row Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174 The Column Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174 The Value Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .175 The Page Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .175 Redefining Your Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176 Case Study: Consolidating and Analyzing Datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176 Building a Pivot Table Using External Data Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .179 Building a Pivot Table with Microsoft Access Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .180

Contents

Building a Pivot Table with SQL Server Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .183 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .187

8 Sharing Pivot Tables with Others . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189 Sharing a Pivot Table with Other Versions of Office . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189 Features Unavailable in Excel 2003 Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .190 Excel 2007 Compatibility Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .190 No Downgrade Path Available from Version 12 Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . .190 Strategies for Sharing Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .190 Saving Pivot Tables to the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191 Publishing Pivot Tables to Excel Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .193 Requirements to Render Spreadsheets with Excel Services . . . . . . . . . . . . . . . . . . . . . . . . . . . .194 Preparing Your Spreadsheet for Excel Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .194 Publishing Your Spreadsheet to Excel Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .194 What the End User Sees in Excel Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .196 What You Cannot Do with Excel Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .197 Viewing the Pivot Table in the Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199

9 Working with and Analyzing OLAP Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .201 What Is OLAP? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .201 Connecting to an OLAP Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .202 Understanding the Structure of an OLAP Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .205 Understanding Limitations of OLAP Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .207 Creating Offline Cubes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .207 Breaking Out of the Pivot Table Mold with Cube Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .211 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .213

10 Enhancing Your Pivot Table Reports with Macros . . . . . . . . . . . . . . . . . . . . . . .215 Why Use Macros with Your Pivot Table Reports? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .215 Recording Your First Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .216 Creating a User Interface with Form Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .218 Altering a Recorded Macro to Add Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .220 Case Study: Synchronizing Two Pivot Tables with One Combo Box . . . . . . . . . . . . . . . . . . . . . . . . . .225 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .229

11 Using VBA to Create Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .231 Introducing VBA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .231 Enabling VBA in Your Copy of Excel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .231 Enabling the Developer Ribbon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .232 Visual Basic Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .232 Visual Basic Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .233 The Macro Recorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .234

vii

viii

Pivot Table Data Crunching for Microsoft Office Excel 2007

Understanding Object-Oriented Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .234 Learning Tricks of the Trade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .234 Writing Code to Handle Any Size Data Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .235 Using Super-Variables: Object Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .236 Understanding Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .236 New in Excel 2007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .237 Building a Pivot Table in Excel VBA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .239 Getting a Sum Instead of a Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .241 Learning Why You Cannot Move or Change Part of a Pivot Report . . . . . . . . . . . . . . . . . . . . . .243 Determining Size of a Finished Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .244 Creating a Report Showing Revenue by Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .246 Eliminating Blank Cells in the Values Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248 Ensuring Table Layout Is Utilized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248 Controlling the Sort Order with AutoSort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248 Changing Default Number Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248 Suppressing Subtotals for Multiple Row Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .249 Suppressing Grand Total for Rows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .250 Handling Additional Annoyances When Creating Your Final Report . . . . . . . . . . . . . . . . . . . . . . . . .250 Creating a New Workbook to Hold the Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .250 Creating a Summary on a Blank Report Worksheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .251 Filling the Outline View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .252 Handling Final Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .252 Adding Subtotals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253 Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .254 Addressing Issues with Two or More Data Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .257 Calculated Data Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .258 Calculated Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .260 Summarizing Date Fields with Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .263 Group by Week . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .265 Using Advanced Pivot Table Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .267 Using AutoShow to Produce Executive Overviews . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .267 Using ShowDetail to Filter a Recordset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .270 Creating Reports for Each Region or Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .272 Manually Filtering Two or More Items in a PivotField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .275 Controlling the Sort Order Manually . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .276 Using Sum, Average, Count, Min, Max, and More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .276 Creating Report Percentages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .277 Percentage of Total . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .277 Percentage Growth from Previous Month . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .278 Percentage of a Specific Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .278 Running Total . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .278 Using New Pivot Table Features in Excel 2007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .279 Using the New Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .279

Contents

Applying a Table Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .284 Changing the Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .285 Applying a Data Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .286 Understanding Special Considerations for Excel 97 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .288 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .289

12 Common Pivot Table Issues and Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .291 Troubleshooting Common Pivot Table Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .291 I keep getting the error “The PivotTable field name is not valid.” . . . . . . . . . . . . . . . . . . . . . . .291 When I refreshed my pivot table, my data disappeared. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .291 My pivot table always uses Count instead of Sum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .292 My pivot table constantly adjusts the columns in my workbook to autofit the headings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .292 The Defer Layout Update option locked me out of other functionality such as sorting, filtering, and grouping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .293 Older versions of Excel do not open my pivot table properly. . . . . . . . . . . . . . . . . . . . . . . . . . . .293 When I try to group a field, I get an error message. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .294 My pivot table shows the same data item twice. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .294 Deleted data items still show up in the filter area. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .295 I refreshed my pivot table, and now my calculated fields are displayed as error values. . . . .296 Common Pivot Table Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .297 How do I make my pivot table refresh automatically? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .297 How do I refresh all pivot tables in a workbook at the same time? . . . . . . . . . . . . . . . . . . . . . .297 How can I sort data items in a unique order that is not ascending or descending? . . . . . . . .298 How do I turn my pivot table into hard data? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .298 Is there an easy way to fill the empty cells left by row fields? . . . . . . . . . . . . . . . . . . . . . . . . . .299 Is there an easy way to fill the empty cells left by row fields in many columns? . . . . . . . . . . .300 Why does my pivot chart exclude months for certain data items? . . . . . . . . . . . . . . . . . . . . . .303 How do I add a rank number field to my pivot table? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .305 How do I hide calculation errors in my pivot table? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .307 How can I reduce the size of my pivot table reports? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .308 How can I easily create a separate pivot table for each market? . . . . . . . . . . . . . . . . . . . . . . . .309 How do I avoid the need to constantly redefine my pivot table’s data range? . . . . . . . . . . . . .310

A Finding Pivot Table Commands on the Ribbon . . . . . . . . . . . . . . . . . . . . . . . . . .315 Inserting a Pivot Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .315 Finding Commands from the Legacy PivotTable Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .316

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .321

ix

About the Authors Bill Jelen is Mr. Excel! He is principal behind the leading Excel website, MrExcel.com. He honed his pivot table wizardry during a 12-year tenure as a financial analyst for a fast growing public computer firm. Armed with only a spreadsheet, he learned how to turn thousands of rows of transactional data into meaningful summaries in record time. He is an accomplished author of books on Excel and is a regular guest on “Call For Help” on TechTV Canada. As an Excel consultant, he has written Excel VBA solutions for hundreds of clients around the English-speaking world. His website hosts over 12 million page views annually. Michael Alexander is a Microsoft Certified Application Developer (MCAD) with over 14 years experience developing business solutions with Microsoft Office, VBA, and .Net. He currently lives in Frisco, Texas, where he works as a senior program manager for a top technology firm. In his spare time, he runs a free tutorial site, www.datapigtechnologies.com, where he shares basic Access and Excel tips with intermediate users.

Dedication Bill Jelen: To Zeke Jelen Mike Alexander: To my lovely wife, Mary, who will open this book just long enough to read this dedication

Acknowledgments Bill Jelen: Thank you to Pito Salas, who invented Lotus Improv, the first desktop product to offer functionality similar to pivot tables. Thanks to Dan Bricklin, Bob Frankston, and Mitch Kapor for being pioneers in the spreadsheet world. Thanks to Dave Gainer and the entire Excel team at Microsoft for bringing pivot tables along to what they are today. Juan Pablo González provided great technical review. Thanks to Mary Ellen, Josh, and Zeke Jelen for tolerating me while I was writing six books simultaneously. My sister, Barb Jelen, provides excellent back office support at MrExcel.com; there is a good chance that she packed and shipped this book to you. Lora White keeps things moving and produces our Podcasts. Thanks to Jerry Kohl at Leegin and everyone who ever asked me for a report back at Telxon, and our clients at MrExcel Consulting; you all contributed to my expertise with pivot tables. Thanks to William Brown at Waterside; Loretta Yates, Andy Beaster, Chuck Hutchinson, and Kevin Howard at Que Publishing. Thanks to Mike Alexander for being a great coauthor.

Mike Alexander: Thank you to Bill Jelen for the opportunity to help write this book. It’s hard to find anyone who has more passion and drive for what he does than Bill Jelen. Thank you to Juan Pablo González for keeping Bill and me honest and sparking some great ideas. Many thanks to Loretta Yates and the many professionals at Que Publishing for all the support during the writing process. A special thank you to Mary for putting up with all my crazy projects this year.

We Want to Hear from You! As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what we’re doing right, what we could do better, what areas you’d like to see us publish in, and any other words of wisdom you’re willing to pass our way. As an associate publisher for Que Publishing, I welcome your comments. You can email or write me directly to let me know what you did or didn’t like about this book—as well as what we can do to make our books better. Please note that I cannot help you with technical problems related to the topic of this book. We do have a User Services group, however, where I will forward specific technical questions related to the book. When you write, please be sure to include this book’s title and author as well as your name, email address, and phone number. I will carefully review your comments and share them with the author and editors who worked on the book. Email:

[email protected]

Mail:

Greg Wiegand Associate Publisher Que Publishing 800 East 96th Street Indianapolis, IN 46240 USA

Reader Services Visit our website and register this book at www.quepublishing.com/register for convenient access to any updates, downloads, or errata that might be available for this book.

Pivot tables are the single most powerful feature in all of Excel. They came along during the 1990s when Microsoft and Lotus were locked in a bitter battle for dominance of the spreadsheet market. The race to continually add enhanced features to their respective products during the mid-90s led to many incredible features, but none as powerful as the pivot table.

INTRODUCTION IN THIS INTRODUCTION What You Will Learn from This Book

. . . . . . . . . . . .1

What Is New in Excel 2007’s Pivot Tables

..... 2

With a pivot table, you can take 1 million rows of transactional data and transform it into a summary report in seconds. If you can drag a mouse, you can create a pivot table. In addition to quickly summarizing and calculating data, pivot tables allow you to change your analysis on the fly by simply moving fields from one area of a report to another.

Skills Required to Use This Book . . . . . . . . . . .2

There is simply no other tool in Excel that gives you the flexibility and analytical power that pivot tables can give you.

Conventions Used in This Book

What You Will Learn from This Book It is widely agreed that close to 50% of Excel users leave 80% of Excel untouched. That is, most users don’t tap into the full potential of Excel’s built-in utilities. Of these utilities, the most prolific by far is the pivot table. Despite the fact that pivot tables have been a cornerstone of Excel for more than 12 years now, they remain one of the most underutilized tools in the entire Microsoft Office Suite. If you have picked up this book, you are savvy enough to have heard of pivot tables or even have used them on occasion. You have a sense that pivot tables have a power that you are not using, and you want to learn how to leverage that power to quickly increase your productivity. Within the first two chapters, you will be able to create basic pivot tables, increase your productivity, and produce reports in minutes instead of hours.

Case Study: Life Before Pivot Tables The Invention of the Pivot Table

........... 2

............... 5

Case Study: Life After Pivot Tables

.............. 7

Sample Files Used in This Book . . . . . . . . . . . .9 . . . . . . . . . . . . . . . . . .9

2

Introduction Within the first seven chapters, you will be able to output complex pivot reports with drilldown capabilities accompanying charts. By the end of the book, you will be able to build a dynamic pivot table reporting system.

What Is New in Excel 2007’s Pivot Tables Microsoft streamlined the pivot table interface to make it easier to use. In the last six versions of Excel, you generally created and modified a pivot table by dragging field names around the worksheet. Excel provided subtle visual clues about where a dropped field would appear, but these clues were too subtle for most. If you accidentally dropped a text field in the data area instead of the row area, disaster would result. Now, in Excel 2007, you can build a pivot table by checking a few boxes. Excel’s IntelliSense figures out the best location for the field. To modify the default, you can drag field names around the PivotTable Field List. Also new in Excel 2007 is the easier interface for sorting and filtering fields in a pivot table. Whereas sorting was formerly hidden three levels deep in the menu system, it is now just one click away from the PivotTable Field List. Formatting such as heat maps, data bars, banded rows, and columns are now available as icons on the Excel 2007 Ribbon. Finally, Microsoft is pushing a high-end server product that allows many people to access data stored in pivot tables. It is no surprise that pivot tables play a key role in the interactivity of Excel Services for SharePoint.

Skills Required to Use This Book We have created a reference that is comprehensive enough for hard-core analysts yet relevant to casual users of Excel. The bulk of the book covers how to use pivot tables in the Excel user interface. The final chapter describes how to create pivot tables in Excel’s powerful VBA macro language. This means that any user who has a firm grasp of the basics (preparing data, copying, pasting, entering simple formulas) should have no problem understanding the concepts in this book.

C A S E S T U DY

Life Before Pivot Tables Imagine that it is 1992.You are using Lotus 1-2-3 or Excel 4.You have thousands of rows of transactional data, as shown in Figure I.1.Your manager asks you to prepare a summary report showing revenue by region and product. In 1992, preparing this report was a daunting task. It required superhuman spreadsheet skills that few could master. Here are the steps you needed to take:

Life Before Pivot Tables

Figure I.1 As a financial analyst in 1992, you are responsible for producing a summary from this dataset.

1. You need to get a list of the unique regions in the dataset. Use the Advanced Filter command with Unique Records Only (see Figure I.2) to extract a list of the unique regions. Figure I.2 Even today, the Advanced Filter command is not a lot of fun to use.

2. You need to get a list of the unique products in the dataset. Use the Advanced Filter command with Unique Records Only a second time to extract a list of the unique products. 3. You need to turn the list of products sideways so that it runs across the columns. Copy the list of unique models. Then choose Edit, Paste Special,Transpose to arrange the products as headings going across the report.You now have a skeleton of the report, as shown in Figure I.3. 4. You could use the DSUM function to total a column based on one criterion, but not based on two criteria.Therefore, you need to abandon typical functions and instead rely on an array formula. Before entering the array formula, set up two fields above the report to hold a sample region and sample model.

3

Introduction

Figure I.3 After using a second Advanced Filter command and choosing Edit, Paste Special,Transpose, you have this skeleton of the final report.You still have a long way to go.

5. In the corner cell of the report, build an array formula to test whether the region column is North and the Model column is 4055T, and if so, add the corresponding row from the Revenue column. After typing this formula, remember to press Ctrl+Shift+Enter; otherwise, the formula will not work.The formula is shown in the formula bar in Figure I.4.

TIP

4

For a complete explanation of two-condition sums using array formulas, see http://www.MrExcel. com/tip031.shtml.

Figure I.4 With the array formula in the corner of the report, you are ready to use the not-so-intuitive Data Table 2 command.

6. You know you’re a hard-core data analyst if you can still imagine pressing the keystrokes for /Data Table 2 in Lotus 1-2-3. Figure I.5 shows the equivalent function in Excel. In Excel 2007, this command is found in Data, Data Tools,What If Analysis, Data Table. 7. Finally, after using two advanced filters and a Paste Special command, writing the hardest formula in the world, and then using the Data Table command, you have the result your manager is looking for, as shown in Figure I.6. If you could pull off this analysis in 10 minutes, you were doing an amazing job. Now, if your manager takes a look at the report and asks you to add Market to the analysis, you are nearly back at square one and are looking at an additional 15 minutes to produce the new report.

The Invention of the Pivot Table

Figure I.5 The Data Table command replicates the formula in the top-left corner of the table but replaces two references in the formula with the headings at the top and left of the report.

Figure I.6 After 10 minutes displaying knowledge of obscure spreadsheet commands, you have produced the needed report.

The Invention of the Pivot Table The concept that led to today’s pivot table came from the halls of the Lotus Development Corporation with a revolutionary spreadsheet program called Lotus Improv. Improv was envisioned in 1986 by Pito Salas of the Advanced Technology Group at Lotus. Realizing that spreadsheets often have patterns of data, Pito concluded that if a user could build a tool that could recognize these patterns, then he could build enhanced data models. Lotus ran with the concept and started developing the next-generation spreadsheet.

5

6

Introduction Pito Salas, inventor of the pivot table concept, is always working on cutting-edge products at http://www.salas.com.

Throughout 1987, Lotus demonstrated its new program to a few companies. In 1988, Steve Jobs saw the program and immediately wanted it developed for his upcoming NeXT computer platform. The program, finally named Lotus Improv, was eventually shipped in 1991 for the NeXT platform. A version for Windows was introduced in 1993. The core concept behind Improv was that data, data views, and formulas should be encapsulated as separate entities and treated as different animals. For the first time in a spreadsheet program, a dataset was given a name that could be grouped into larger categories. This naming and grouping capability paved the way for the most powerful feature in Improv: rearranging data. With Improv, a user could define and store a set of categories and then change the view by simply dragging the category names with the mouse. The user could also create totals and group summaries. Microsoft eventually picked up on this concept in its pivot table functionality in Excel 5. Years later, with the release of Excel 97, Microsoft offered users an enhanced pivot table wizard and key improvements to pivot table functionality, such as the capability to add calculated fields. Excel 97 also opened the pivot cache to developers, fundamentally changing the way pivot tables are created and managed. Microsoft introduced the pivot chart with Excel 2000, providing users a way to represent pivot tables graphically. Since Excel 2000, changes made to pivot tables have been mainly cosmetic, much to the chagrin of pivot table fans everywhere.

Life After Pivot Tables

C A S E S T U DY

Life After Pivot Tables You have 600,000 rows of transactional data, as discussed in the previous case study.Your manager asks you to prepare a summary report showing revenue by Region and Model. Luckily, you have pivot tables at your disposal. Here are the steps you would follow today: 1. Select a single cell in your dataset. Choose PivotTable from the Insert tab. Click OK.You are given a blank pivot table, as shown in Figure I.7. Figure I.7 After three mouse clicks, you have a blank pivot table report.Three more mouse clicks to go.

2. From the Pivot Table Field List, click the Region check box. Excel adds it to the left side of the pivot table. Click the check box next to Product_Number. In the lower portion of the dialog box, drag Product_Description from the Row Labels section to the Column Labels section. Click the Sales_Amount field in the top of the Pivot Table Field List. After a total of six mouse clicks, you have the required report, as shown in Figure I.8.

7

8

Introduction

Figure I.8 Add three fields to the report.

If you are racing, you can actually create the report shown in Figure I.8 in exactly 10 seconds.This is an amazing accomplishment. Realistically, it would take you about 50 seconds at normal speed to create the report. If you are a spreadsheet wizard and are instead following the steps in the previous case study, the non–pivot table solution would take you at least 12 times longer. Further, when your manager comes back with the request to add Market to the analysis, you need just seconds to check the Market field in the PivotTable Field List to add it to the report, as shown in Figure I.9. Figure I.9 Creating a new report with the Market field is as simple as choosing the field from the list.

Conventions Used in This Book

Sample Files Used in This Book All data files used throughout this book are available for download from http://www. mrexcel.com/pivotbookdata2007.html.

Conventions Used in This Book This book follows certain conventions: ■

Monospace—Text messages you see onscreen or code appears in a monospace font.



Bold Monospace—Text you type appears in a bold,



Italic—New and important terms appear in italics.



Initial Caps—Ribbon names, dialog box names, and dialog box elements are presented with initial capital letters so that you can identify them easily.

monospace

font.

Referring to Ribbon Commands Office 2007 features a new interface called the Ribbon. The Ribbon in Excel 2007 is composed of several tabs labeled Home, Insert, Page Layout, and so on. When you click on the Page Layout tab, you see the icons available on the Page Layout tab. When the active cell is inside a pivot table, two new tabs appear on the Ribbon. In the help files, Microsoft has been calling these tabs “PivotTable Tools | Options” and “PivotTable Tools | Design.” For convenience, this book refers to these elements as the Options tab and the Design tab, respectively. Within each Ribbon, the icons are arranged into logical groups. The name of each group is shown in a colored band at the bottom of the group. When referring to a specific icon, the book mentions the group name. To refer to the item in Figure I.10, this book says, “Click the Field Settings icon in the Active Field group of the Options tab.” Ribbon name

Field Settings icon

Figure I.10 Icons are referred to by the ribbon tab, the group name, and then the icon name. Group name

In some cases, the Ribbon icon leads to a drop-down with additional choices. In these cases, the book lists the hierarchy of Ribbon, Group, Icon, Menu Choice, Submenu Choice. For example, in Figure I.11, the shorthand specifies “Choose Design, Layout, Blank Rows, Remove Blank Line After Each Item.”

9

Introduction

Menu choice

Figure I.11 For shorthand, instructions might say Ribbon, Group, Icon, Menu Choice, Submenu Choice.

Special Elements

NOTE

This book contains the following special elements:

Notes provide additional information outside the main thread of the chapter discussion that might still be useful for you to know.

TIP

10

Tips provide you with quick workarounds and time-saving techniques to help you do your work more efficiently.

CAUTION Cautions warn you about potential pitfalls you might encounter. Pay attention to them because they alert you to problems that otherwise could cause you hours of frustration.

C A S E S T U DY Case studies provide a real-world look at topics previously introduced in the chapter.

Pivot Table Fundamentals What Is a Pivot Table? Imagine that Excel is a large toolbox that contains different tools at your disposal. The pivot table is essentially one tool in your Excel toolbox. If a pivot table were indeed a physical tool that you could hold in your hand, a kaleidoscope would most accurately represent it. When you look through a kaleidoscope at an object, you see that object in a different way. You can turn the kaleidoscope to move around the details of the object. The object itself doesn’t change, and it’s not connected to the kaleidoscope. The kaleidoscope is simply a tool you use to create a unique perspective on an ordinary object. Think of a pivot table as a kaleidoscope that is pointed at your dataset. When you look at your dataset through a pivot table, you have the opportunity to see details in your data you may not have noticed before. Furthermore, you can turn your pivot table to see your data from different perspectives. The dataset itself doesn’t change, and it’s not connected to the pivot table. The pivot table is simply a tool you are using to create a unique perspective on your data. A pivot table allows you to create an interactive view of your dataset. We call this view a pivot table report. With a pivot table report, you can quickly and easily categorize your data into groups, summarize large amounts of data into meaningful information, and perform a wide variety of calculations in a fraction of the time it takes by hand. But the real power of a pivot table report is that you can interactively drag and drop fields within your report, dynamically changing your perspective and recalculating totals to fit your current view.

1 IN THIS CHAPTER What Is a Pivot Table? . . . . . . . . . . . . . . . . . . . .11 Why Should You Use a Pivot Table? . . . . . . . . .12 When Should You Use a Pivot Table? . . . . . . . .13 The Anatomy of a Pivot Table . . . . . . . . . . . . . .14 Pivot Tables Behind the Scenes . . . . . . . . . . . .16 Limitations of Pivot Table Reports . . . . . . . . .17 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19

12

Chapter 1

Pivot Table Fundamentals

Why Should You Use a Pivot Table? 1

As a rule, your dealings in Excel can be split into two categories: calculating data and shaping (formatting) data. Although many built-in tools and formulas facilitate both of these tasks, the pivot table is often the fastest and most efficient way to calculate and shape data. Let’s look at one simple scenario that illustrates this point. You have just given your manager some revenue information by month, and he has predictably asked for more information. He adds a note to the worksheet and emails it back to you. As you can see in Figure 1.1, he would like you to add a line that shows credits by month.

Figure 1.1 Your manager predictably changes his request after you provide the first pass of a report.

To meet this new requirement, you run a query from your legacy system that will provide the needed data. As usual, the data is formatted specifically to make you suffer. Instead of data by month, the legacy system provides detailed transactional data by day, as shown in Figure 1.2.

Figure 1.2 The data from the legacy system is by day instead of by month.

Your challenge is to calculate the total dollar amount of credits by month and shape the results into an extract that fits the format of the original report. The final extract should look like the data shown in Figure 1.3. Creating the extract manually would take 18 mouse clicks and three keystrokes: Format dates to month: three clicks Create subtotals: four clicks

When Should You Use a Pivot Table?

13

Extract subtotals: six clicks, three keystrokes Transpose vertical to horizontal: five clicks

1

Figure 1.3 Your goal is to produce a summary by month and transpose the data to a horizontal format.

In contrast, creating the extract with a pivot table would take nine mouse clicks: Create the pivot table report: five clicks Group dates into months: three clicks Transpose vertical to horizontal: one click Both methods give you the same extract, which can be pasted into the final report, as shown in Figure 1.4.

Figure 1.4 After adding credits to the report, you can calculate net revenue.

Using a pivot table to accomplish this task not only cuts down the number of actions by more than half, but also reduces the possibility of human error. Over and above that, using a pivot table allows for the quick and easy shaping and formatting of the data. What this example shows is that using a pivot table is not just about calculating and summarizing your data. Pivot tables can often help you do a number of tasks faster and better than conventional functions and formulas. For example, you can use pivot tables to instantly transpose large groups of data vertically or horizontally. You can use pivot tables to quickly find and count the unique values in your data. You can also use pivot tables to prepare your data to be used in charts. The bottom line is that pivot tables can help you dramatically increase your efficiency and decrease your errors on a number of tasks you may have to accomplish with Excel. Pivot tables can’t do everything for you, but knowing how to use just the basics of pivot table functionality can take your data analysis and productivity to a new level.

When Should You Use a Pivot Table? Large datasets, ever-changing impromptu data requests, and multilayered reporting are absolute productivity killers if you have to tackle them by hand. Going hand-to-hand combat with one of these not only is time consuming, but also opens up the possibility of an

14

Chapter 1

Pivot Table Fundamentals

untold number of errors in your analysis. So how do you recognize when to use a pivot table before it’s too late?

1

Generally, a pivot table would serve you well in any of the following situations: ■

You have a large amount of transactional data that has become increasingly difficult to analyze and summarize in a meaningful way.



You need to find relationships and groupings within your data.



You need to find a list of unique values for one field in your data.



You need to find data trends using various time periods.



You anticipate frequent requests for changes to your data analysis.



You need to create subtotals that frequently include new additions.



You need to organize your data into a format that’s easy to chart.

The Anatomy of a Pivot Table Because the anatomy of a pivot table is what gives it its flexibility and, indeed, its ultimate functionality, truly understanding pivot tables would be difficult without understanding their basic structure. A pivot table is composed of four areas. The data you place in these areas defines both the utility and appearance of the pivot table. Keeping in mind that you will go through the process of creating a pivot table in the next chapter, let’s prepare by taking a closer look at the four areas and the functionality around them.

Values Area The values area is shown in Figure 1.5. It is a large rectangular area below and to the right of the headings. In this example, the values area contains a sum of the revenue field. Values area

Figure 1.5 The heart of the pivot table is the values area. This area typically includes a total of one or more numeric fields.

The values area is the area that calculates. This area is required to have at least one field and one calculation on that field in it. The data fields that you drop here are those that you

The Anatomy of a Pivot Table

15

want to measure or calculate. The values area might include Sum of Revenue, Count of Units, and Average of Price. It is also possible to have the same field dropped in the values area twice, but with different calculations. A marketing manager might want to see Minimum of Price, Average Price, and Maximum of Price.

Row Area The row area is shown in Figure 1.6. It is composed of the headings that go down the left side of the pivot table.

Figure 1.6 The headings down the left side of the pivot table make up the row area of the pivot table.

Row area

Dropping a field into the row area displays the unique values from that field down the rows of the left side of the pivot table. The row area typically has at least one field, although it is possible to have no fields. The example earlier in the chapter where you needed to produce a one-line report of credits is an example where there are no row fields. The types of data fields that you would drop here include those that you want to group and categorize—for example, Products, Names, and Locations.

Column Area The column area is composed of headings that stretch across the top of columns in the pivot table. In the pivot table in Figure 1.7, the month field is in the column area. Dropping fields into the column area would display your items in column-oriented perspective. The column area is ideal to show trending over time. The types of data fields that you would drop here include those you want to trend or show side by side—for example, Months, Periods, and Years.

1

16

Chapter 1

Pivot Table Fundamentals

Column area

Figure 1.7 1

The column area stretches across the top of the columns. In this example, it contains the unique list of months in your dataset.

Report Filter Area The report filter area is an optional set of one or more drop-downs at the top of the pivot table. In Figure 1.8, the report filter area contains the Region field, and the pivot table is set to show all regions. Report filter area

Figure 1.8 Report filter fields are great for quickly filtering a report.The Region drop-down in cell B1 would allow you to print this report for one particular region manager.

Dropping fields into the report filter area would allow you to filter the data items in your fields. The report filter area is optional and comes in handy when you need to filter your results dynamically. The types of data fields that you would drop here include those that you want to isolate and focus on—for example, Regions, Line of Business, and Employees.

Pivot Tables Behind the Scenes It’s important to know that pivot tables do come with a few file space and memory implications for your system. To get an idea of what this means, let’s look at what happens behind the scenes when you create a pivot table.

Limitations of Pivot Table Reports When you initiate the creation of a pivot table report, Excel takes a snapshot of your dataset and stores it in a pivot cache. A pivot cache is nothing more than a special memory subsystem in which your data source is duplicated for quick access. Although the pivot cache is not a physical object that you can see, you can think of it as a container that stores the snapshot of the data source. Each pivot table report you create from a separate data source creates its own pivot cache that increases your memory usage and file size. The increase in memory usage and file size depends on the size of the original data source that is being duplicated to create the pivot cache. Your pivot table report is essentially a view that gets its data solely from the pivot cache. This means that your pivot table report and your data source are disconnected.

CAUTION Any changes you make to your data source are not picked up by your pivot table report until you take another snapshot of the data source or “refresh” the pivot cache. Refreshing is easy: Simply right-click on the pivot table and click Refresh Data.You can also select the large Refresh button on the Options tab.

The benefit of working against the pivot cache and not your original data source is optimization. Any changes you make to the pivot table report, such as rearranging fields, adding new fields, or hiding items, are made rapidly and with minimal overhead.

Limitations of Pivot Table Reports Before discussing the limitations of pivot table reports, we should note that Excel 2007 offers a dramatic increase in the number of rows and columns allowed in one worksheet. Indeed, you may have upgraded specifically because Excel 2007 offers over 1 million rows and 16,384 columns per worksheet. This increase in limits has a ripple effect on several of the tools and functions in Excel, forcing limitation increases in many areas including pivot tables. Table 1.1 highlights the changes in pivot table limits from Excel 2000 to Excel 2007. Whereas some of these limitations remain constant, others are highly dependent on available system memory.

Table 1.1 Pivot Table Limitations Category

Excel 2000

Excel 2002/2003

Excel 2007

Number of Row Fields (could be limited by available memory)

Limited by available memory

Limited by available memory

1,048,576

Number of Column Fields

256

256

16,384

continues

17

1

18

Chapter 1

Pivot Table Fundamentals

Table 1.1 Continued 1

Category

Excel 2000

Excel 2002/2003

Excel 2007

Number of Page Fields

256

256

16,384

Number of Data Fields

256

256

16,384

Number of Unique Items in a Single Pivot Field (could be limited by available memory)

8,000

32,500

1,048,576

Number of Calculated Items

Limited by available memory

Limited by available memory

Limited by available memory

Number of Pivot Table Reports on One Worksheet

Limited by available memory

Limited by available memory

Limited by available memory

A Word About Compatibility As you can imagine, the extraordinary increases in pivot table limitations lead to some serious compatibility questions. For instance, what if you create a pivot table that contains more than 256 column fields and more than 32,500 unique data items? How are users with previous versions of Excel affected? Luckily, Excel 2007 comes with some precautionary measures that can help you avoid compatibility issues. The first precautionary measure is Compatibility mode. Compatibility mode is a state that Excel 2007 automatically enters when opening an .xls file. When Excel 2007 is in Compatibility mode, it artificially takes on the limitations of Excel 2003. This means while you are working with an .xls file, you cannot exceed any of the Excel 2003 pivot table limitations shown in Table 1.1. This effectively prevents you from unwittingly creating a pivot table that is not compatible with previous versions of Excel. If you want to get out of Compatibility mode, you have to save the .xls file as one of Excel’s new file formats (.xlsx or .xlsm).

CAUTION Beware of the upgrade option on the Office Icon menu. Although this command is designed to convert a file from Excel 2003 to Excel 2007, it actually deletes the Excel 2003 copy of the file.

The second precautionary measure is Excel’s Compatibility Checker. The Compatibility Checker is a built-in tool that checks for any compatibility issues when you try to save an Excel 2007 workbook as an .xls file. If your pivot table exceeds the bounds of Excel 2003 limitations, the Compatibility Checker alerts you with a dialog box similar to the one shown in Figure 1.9.

Next Steps

19

Figure 1.9 The Compatibility Checker alerts you of any compatibility issues before you save to a previous version of Excel.

1

NOTE

With this dialog box, Excel gives you the option of saving your pivot data as hard values in the new .xls file. If you choose to do so, the data from your pivot table is saved as hard values, but the pivot table object and the pivot cache are lost.

For information on Excel 2007’s compatibility tools, pick up Que Publishing’s Special Edition Using Microsoft Excel 2007 by Bill Jelen.

Next Steps In the next chapter, you learn how to prepare your data to be used by a pivot table and walk through creating your first pivot table report with the Pivot Table Wizard.

This page intentionally left blank

Creating a Basic Pivot Table Preparing Your Data for Pivot Table Reporting When you have a family portrait taken, the photographer takes time to make sure that the lighting is right, the poses are natural, and everyone smiles his or her best smile. This preparation ensures that the resulting photo is effective in its purpose. When you create a pivot table report, you’re the photographer, taking a snapshot of your data. Taking time to make sure your data looks its best ensures that your pivot table report is effective in accomplishing the task at hand. One of the benefits of working in a spreadsheet is that you have the flexibility of laying out your data to suit your needs. Indeed, the layout you choose depends heavily on the task at hand. However, many of the data layouts used for presentations are not appropriate when used as the source data for a pivot table report. As you read the next section that goes into preparing your data, keep in mind that pivot tables have only one hard rule as it pertains to your data source: Your data source must have column headings, which are labels in the first row of your data describing the information in each column. If this is not the case, your pivot table report cannot be created. However, just because your pivot table report is created successfully does not mean that it’s effective. A host of things can go wrong as a result of bad data preparation—from inaccurate reporting to problems with grouping and sorting. Let’s look at a few of the steps you can take to ensure you end up with a viable pivot table report.

2 IN THIS CHAPTER Preparing Your Data for Pivot Table Reporting . . . . . . . . . . . . . . . . . . . . . . . . .21 Case Study: Cleaning Up Data for Pivot Table Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . .25 Creating a Basic Pivot Table . . . . . . . . . . . . . . .26 Case Study: Analyzing Activity by Market . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35 Keeping Up with Changes in Your Data Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39 Sharing the Pivot Cache . . . . . . . . . . . . . . . . . .41 Saving Time with New Pivot Table Tools . . . . .42 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44

22

Chapter 2

Creating a Basic Pivot Table

Ensure Your Data Is in a Tabular Layout A perfect layout for the source data in a pivot table is a tabular layout. In tabular layout, there are no blank rows or columns. Every column has a heading. Every field has a value in every row. Columns do not contain repeating groups of data.

Tabular layouts are database-centric, meaning that you would most commonly find these types of layouts in databases. These layouts are designed to store and maintain large amounts of data in a well-structured, scalable format.

Figure 2.1 This data is structured properly for use as a pivot table source.

TIP

2

Figure 2.1 shows an example of data structured properly for a pivot table. There are headings for each column. Even though the values in D2:D6 are all the same model, the model number appears in each cell. Month data is organized down the page instead of across the columns.

You might work for a manager who demands that the column labels be split into two rows. For example, he may want the heading Gross Margin to be split with Gross in row 1 and Margin in row 2. Because pivot tables require a unique heading one row high, your manager’s preference can be problematic.To overcome this problem, start typing your heading; for example, type Gross. Before leaving the cell, press Alt+Enter and then type Margin.The result is a single cell that contains two lines of data.

Avoid Storing Data in Section Headings Examine the data in Figure 2.2. This spreadsheet shows a report of sales by month and model for the North region of a company. Because the data in rows 2 through 24 pertains to the North region, the author of the worksheet put a single cell with North in B1. This approach is effective for display of the data, but not effective when used as a pivot table data source.

Preparing Your Data for Pivot Table Reporting

23

Figure 2.2 Region and model data are not formatted properly in this dataset.

2

Also in Figure 2.2, the author was very creative with the model information. The data in rows 2 through 6 applies to Model 2500P, so the author entered this value once in A2 and then applied a fancy vertical format combined with Merge Cells to create an interesting look for the report. Again, although this is a cool format, it is not useful for pivot table reporting. Also, the worksheet in Figure 2.2 is missing column headings. You can guess that column A is Model, column B is Month, and column C is Sales, but for Excel to create a pivot table, this information must be included in the first row of the data.

Avoid Repeating Groups as Columns The format shown in Figure 2.3 is common. A time dimension is presented across several columns. Although it is possible to create a pivot table from this data, this format is not ideal. The problem is that the headings spread across the top of the table pull double duty as column labels and actual data values. In a pivot table, this format would force you to manage and maintain six fields, each representing a different month.

Eliminate Gaps and Blank Cells in Your Data Source Delete all empty columns within your data source. An empty column in the middle of your data source causes your pivot table to fail on creation because the blank column, in most cases, does not have a column name.

24

Chapter 2

Creating a Basic Pivot Table

Figure 2.3 This matrix format is common but not effective for pivot tables.The Month field is spread across several columns of the report.

2 Delete all empty rows within your data source. Empty rows may cause you to inadvertently leave out a large portion of your data range, making your pivot table report incomplete.

NOTE

Fill in as many blank cells in your data source as possible. Although filling in cells is not required to create a workable pivot table, blank cells in and of themselves are generally errors waiting to happen. So a good practice is to represent missing values with some logical missing value code wherever possible.

Although this may seem like a step backwards for those of you who are trying to create a nicely formatted report, it will pay off in the end. Once you are able to create a pivot table, there will be plenty of opportunity to apply some pleasant formatting. In Chapter 3, you will discover how to apply styles formatting to your pivot tables.

Apply Appropriate Type Formatting to Your Fields Formatting your fields appropriately helps you avoid a whole host of possible issues from inaccurate reporting to problems with grouping and sorting. Make certain that any fields to be used in calculations are explicitly formatted as a number, currency, or any other format appropriate for use in mathematical functions. Fields containing dates should also be formatted as any one of the available date formats.

Summary of Good Data Source Design The attributes of an effective tabular design are as follows: ■

The first row of your data source is made up of field labels or headings that describe the information in each column.



Each column in your data source represents a unique category of data.



Each row in your data source represents individual items in each column.



None of the column names in your data source double as data items that will be used as filters or query criteria (that is, names of months, dates, years, names of locations, names of employees).

Cleaning Up Data for Pivot Table Analysis

25

C A S E S T U DY

Cleaning Up Data for Pivot Table Analysis The worksheet shown in Figure 2.4 is a great-looking report. However, it cannot be effectively used as a data source for a pivot table. Can you identify the problems with this dataset? Figure 2.4 Someone spent a lot of time formatting this report to look good, but what problems prevent it from being used as a data source for a pivot table?

2

1. The model information does not have its own column. Model information appears in the Region column.To correct this problem, insert a new column for Model and include the model number on every row. 2. There are blank columns and rows in the data. Column D should be deleted.The blank rows between models (such as rows 7 and 15) also should be deleted.

TIP

3. Blank cells present the data in an outline format.The person reading this worksheet would probably assume that cells B10:B11 are in the New England market and cell A11 is in the North region.These blank cells need to be filled in with the values from above.

Here’s a trick for filling in the blank cells. Select the entire range of data.Then select the Home tab on the Ribbon and choose the Find & Select icon from the Editing group.This brings up a menu from which you select Go To Special. In the Go To Special dialog box, select Blanks.With all the blank cells selected, start a formula by typing the equal sign (=), press the up arrow on your keyboard, and then press Ctrl+Enter to fill this formula in all blank cells. Remember to copy and paste special values to convert the formulas to values.

26

Chapter 2

Creating a Basic Pivot Table

TIP

4. The worksheet presents one data column—the data containing month—as several columns in the worksheet. Columns E through I need to be reformatted as two columns. Place the month name in one column and the sales for that month in the next column.This step either requires a fair amount of copying and pasting or a few lines of VBA macro code.

For a great book on learning VBA macro programming, read Que Publishing’s VBA and Macros for Microsoft Excel by Bill Jelen and Tracy Syrstad. It is another book in this Business Solutions series.

2 After you make the four changes described here, the data is ready for use as a pivot table data source. As you can see in Figure 2.5, every column has a heading.There are no blank cells, rows, or columns in the data.The monthly data is now presented down column E instead of across several columns. Figure 2.5 Although this data will take up six times as many rows, it is perfectly formatted for pivot table analysis.

Creating a Basic Pivot Table

TIP

Now that you have a good understanding of the importance of a well-structured data source, let’s walk through creating a basic pivot table.

The sample dataset used throughout this book is available for download at www.MrExcel.com/ pivotbookdata2007.html.

To start, click on any single cell in your data source. This ensures that the pivot table captures the range of your data source by default. Next, select the Insert tab and find the Tables group. In the Tables group, select PivotTable and then choose PivotTable from the drop-down list. Figure 2.6 demonstrates how to start a pivot table.

Creating a Basic Pivot Table

27

Figure 2.6 Start a pivot table by selecting PivotTable from the Insert tab.

2

Choosing these options activates the Create PivotTable dialog box, shown in Figure 2.7.

Figure 2.7

NOTE

The Create PivotTable dialog box replaces the classic PivotTable and PivotChart Wizard.

There are other ways to activate the Create PivotTable dialog box. Clicking the PivotTable icon on the Insert tab activates the Create PivotTable dialog box.You can also press the hotkeys Alt+N+V+T to start a pivot table. A more roundabout way is to format your dataset as a table and then choose the Summarize with Pivot command.To do this, place your cursor inside your dataset and select Format as Table from the Styles group in the Home tab. After your table has been formatted, place your cursor anywhere inside your dataset to activate the Table Tools tab.There you can select the Summarize with Pivot option in the Tools group.

Where Have All the Wizards Gone? As you look at Figure 2.7, you may notice that it doesn’t look like the old PivotTable and PivotChart Wizard found in the previous versions of Excel.The reason is that it’s not a wizard at all. Microsoft has actually abandoned the classic multistep wizard for a more streamlined one-step dialog box.

28

Chapter 2

Creating a Basic Pivot Table

The problem with the classic wizard was that, by the time most first-time users reached step 2, they were either confused or intimidated. Although each subsequent version of Excel has tried to simplify the process of creating a pivot table, the multistep wizard itself ultimately introduced too much complexity for many users. In contrast, Excel 2007’s one-step dialog box presents you with only the minimum requirements necessary to create the pivot table, making for a far less intimidating process. As you can see in Figure 2.8, the Create PivotTable dialog box asks you only two questions: where’s the data that you want to analyze, and where do you want to put the pivot table?

2 Figure 2.8 The Create PivotTable dialog box asks you only two questions.



Choose the Data That You Want to Analyze—In this section, you tell Excel where your dataset is. You can either specify a dataset that is located within your workbook, or you can tell Excel to look for an external dataset. As you can see in Figure 2.8, Excel is smart enough to read your dataset and fill in the range for you. However, you always should take note of this to ensure you are capturing all your data.



Choose Where You Want the PivotTable Report to Be Placed—In this section, you tell Excel where you want your pivot table to be placed. This is set to New Worksheet by default, meaning your pivot table will be placed in a new worksheet within the current workbook. You will rarely change this setting because there are relatively few times you’ll need your pivot table to be placed in a specific location.

After you have answered the two questions in the Create PivotTable dialog box, simply click the OK button. At this point, Excel adds a new worksheet that contains an empty pivot table report. Next to that is the PivotTable Field List dialog box, illustrated in Figure 2.9. This dialog box helps you build your pivot table.

Finding the PivotTable Field List The PivotTable Field List dialog box is your main work area in Excel 2007.This is the place where you add fields and make changes to your pivot table report. By default, this dialog box pops up when you place your cursor anywhere inside your pivot table. However, if you explicitly close this dialog box, you override the default and essentially tell the dialog box not to activate when you are in the pivot table.

Creating a Basic Pivot Table

29

If clicking on the pivot table does not activate the PivotTable Field List dialog box, you can manually activate it by rightclicking anywhere inside the pivot table and selecting Show Field List.You can also click on the large Field List icon on the Options ribbon. Figure 2.9 You use the PivotTable Field List dialog box to build your pivot table.

2

Adding Fields to the Report

TIP

The idea here is to add the fields you need into the pivot table by using the four “drop zones” found in the PivotTable Field List: Report Filter, Column Labels, Row Labels, and Values. These drop zones, which correspond to the four areas of the pivot table, are used to populate your pivot table with data.

Review Chapter 1,“Pivot Table Fundamentals,” for a refresher on the four areas of a pivot table.



Report Filter—Adding a field to the Report Filter drop zone includes that field in the filter area of your pivot table, allowing you to filter on its unique data items.



Column Labels—Adding a field into the Column Labels drop zone displays the unique values from that field across the top of the pivot table.



Row Labels—Adding a field into the Row Labels drop zone displays the unique values from that field down the left side of the pivot table.

30

Chapter 2

Creating a Basic Pivot Table



Values—Adding a field into the Values drop zone includes that field in the values area of your pivot table, allowing you to perform a specified calculation using the values in the field.

Now let’s pause a moment and go over some fundamentals of laying out your pivot table report. This is generally the point where most new users get stuck. How do you know which field goes where?

2

Before you start dropping fields into the various drop zones, ask yourself two questions: What am I measuring? and How do I want to see it? The answer to the first question tells you which fields in your data source you need to work with, and the answer to the second question tells you where to place the fields. For your first pivot table report, you want to measure the dollar sales by region. This automatically tells you that you need to work with the Sales_Amount field and the Region field. How do you want to see it? You want regions to go down the left side of the report and the sales amount to be calculated next to each region. To achieve this effect, you need to add the Region field to the Row Labels drop zone and add the Sales_Amount field to the Values drop zone. Find the Region field in the field list, as shown in Figure 2.10.

Figure 2.10 Find the field you want to add to your pivot table.

Place a check in the check box next to the field. As you can see in Figure 2.11, not only is the field automatically added to the Row Labels drop zone, but your pivot table is updated to show the unique region names.

Creating a Basic Pivot Table

31

Figure 2.11 Place a check next to the Region field to automatically add that field to your pivot table.

2

Now that you have regions in your pivot table, it’s time to add in the dollar sales. To do that, simply find the Sales_Amount field and place a check next to it. As Figure 2.12 illustrates, the Sales_Amount field is automatically added to the Values drop zone, and your pivot table report now shows the total dollar sales for each region.

Figure 2.12 Place a check next to the Sales_Amount field to add data to your pivot table report.

At this point, you have created your first pivot table report!

32

Chapter 2

Creating a Basic Pivot Table

How Does Excel Know Where Your Fields Go? As you’ve just experienced, the new PivotTable Field List interface allows you to add the fields to your pivot table by simply placing a check next to the field name. Excel automatically adds the checked fields to the pivot table.The question is how Excel knows in which drop zone to put the fields you check.The answer is that Excel doesn’t really know which drop zone to use; it makes a decision based on data type. Here’s how it works.When you place a check next to a field, Excel evaluates the data type for that field. If the data type is numeric, Excel places the field into the Values drop zone; otherwise, Excel places the field into the Row Labels drop zone.This placement obviously underlines the importance of correctly assigning the data types for your fields. 2

CAUTION Watch out for blanks in your numeric fields. If you have even one blank cell in a numeric field, Excel reads that cell as a Text field.

Adding Layers to Your Pivot Table Now you can add another layer of analysis to your report. This time you want to measure the amount of dollar sales each region earned by business segment. Because your pivot table already contains the Region and Sales_Amount fields, all you have to do is place a check next to the Business_Segment field. As you can see in Figure 2.13, your pivot table automatically added a layer for Business Segment and refreshed the calculations to include subtotals for each region. Because the data is stored efficiently in the pivot cache, this change took less than a second.

Figure 2.13 Before pivot tables, adding layers to analyses would have required hours of work and complex formulas.

Rearranging Your Pivot Table Suppose this view doesn’t work for your manager. He wants to see business segments across the top of the pivot table report. To rearrange them, simply drag the Business_Segment

Creating a Basic Pivot Table

33

field from the Row Labels drop zone to the Column Labels drop zone, as illustrated in Figure 2.14.

Figure 2.14 Rearranging a pivot table is as simple as dragging fields from one drop zone to another.

NOTE

2

You don’t have to move your fields into a drop zone to be able to drag them around.You can actually drag fields directly from the field list into the desired drop zone.You can also move a field into a drop zone by using that field’s context menu: Click the black triangle next to the field name and then select the desired drop zone.

Instantly, the report is restructured, as shown in Figure 2.15.

Creating a Report Filter Often, you may be asked to produce reports for one particular region, market, or product. Instead of building separate pivot table reports for every possible analysis scenario, you can use the Filter field to create a report filter. For example, you can create a region filter by simply dragging the Region field to the Report Filter drop zone. This way, you can analyze one particular region. Figure 2.16 shows the totals for just the North region.

34

Chapter 2

Creating a Basic Pivot Table

Figure 2.15 Your business segments are now column oriented.

2

Figure 2.16 With this setup, you not only can see revenues by line of business clearly, but also can click on the Region drop-down to focus on one region.

Longing for Drag-and-Drop Functionality? One of the major complaints long-time Excellers will undoubtedly have with Excel 2007 is that you can no longer drag and drop fields directly onto the pivot table layout.This functionality is allowed only within the PivotTable Field List dialog box (dragging into drop zones).The good news, however, is that Microsoft has provided the option of working with a classic pivot table layout, which enables the drag-and-drop functionality. To activate the classic pivot table layout, right-click anywhere inside the pivot table and select Table Options. In the Table Options dialog box, select the Display tab and place a check next to Classic PivotTable Layout, as demonstrated in Figure 2.17. Click the OK button to apply the change.

Analyzing Activity by Market

35

Figure 2.17 Place a check next to Classic PivotTable Layout.

2

At this point, you can drag and drop fields directly onto your pivot table layout. Unfortunately, this setting is not global.That is, you have to go through the same steps to apply the classic layout to each new pivot table you create. However, this setting persists when a pivot table is copied.

C A S E S T U DY

Analyzing Activity by Market Your organization has 14 markets that sell products revolving around six types of facility services.You have been asked to build a report that breaks out each market, highlighting the dollar sales by each product.You are starting with an intimidating transaction table that contains more than 68,000 rows of data.To start your report, do the following: 1. Place your cursor inside your dataset, select the Insert tab, click PivotTable, and then choose PivotTable from the drop-down list. 2. When the Create PivotTable dialog box activates, simply click the OK button. At this point, you should see an empty pivot table with the field list, as shown in Figure 2.18. 3. Find the Market field in the PivotTable Field List and place a check in the box next to it.The Market field immediately appears in the Row Labels area, as illustrated in Figure 2.19. Now that you have your market names, it’s time to calculate the total dollar sales for each market. 4. Find the Sales_Amount field in the PivotTable Field List and place a check in the box next to it.The Sales_Amount field automatically appears in the Values drop zone, as illustrated in Figure 2.20. 5. To get the product breakouts, find the Product_Description field in the PivotTable Field List and drag it into the Column Labels drop zone, as demonstrated here in Figure 2.21.

36

Chapter 2

Creating a Basic Pivot Table

Figure 2.18 The beginnings of your pivot table report.

2

Figure 2.19 With one click, you get a list of the unique markets in your 68,000 rows of data.

Analyzing Activity by Market

37

Figure 2.20 Add the Sales_Amount field.

2

Figure 2.21 Drag the Product_Description field into the Column Labels drop zone.

38

Chapter 2

Creating a Basic Pivot Table

In five easy steps, you have calculated and designed a report that satisfies the requirements given to you. After a little formatting, your pivot table report should look similar to the one shown in Figure 2.22. You can go the extra mile and add one more dimension to your pivot table report to allow for analysis by region. Choose any cell in your pivot table report to redisplay the PivotTable Field List. Drag the Region field into the Report Filter drop zone, as shown in Figure 2.23.

TIP

2

If clicking on the pivot table does not activate the PivotTable Field List dialog box, right-click anywhere inside the pivot table and select Show Field List.

With the Region field placed into the filter area, you can now create separate reports by region if needed. Figure 2.24 demonstrates how selecting the drop-down in the pivot table filter area allows you to select a region by which to filter. Lest you lose sight of the analytical power you just displayed, keep in mind that your data source has more than 68,000 rows and 17 columns, which is a hefty set of data by Excel standards. Despite the amount of data, you produced a relatively robust analysis in a matter of minutes. Figure 2.22 This summary can be created in less than a minute.

Keeping Up with Changes in Your Data Source

39

Figure 2.23 Add another reporting dimension by dragging the Region field to the Report Filter drop zone.

2

Figure 2.24 Select any region from the filter area drop-down to filter the data in the pivot table for just that region.

Keeping Up with Changes in Your Data Source Let’s go back to the family portrait analogy. As years go by, your family will change in appearance and may even grow to include some new members. The family portrait that was taken years ago remains static and no longer represents the family today. So another portrait will have to be taken. As time goes by, your data may change and grow with newly added rows and columns. However, the pivot cache that feeds your pivot table report is disconnected from your data source, so it cannot represent any of the changes you make to your date source until you take another snapshot.

40

Chapter 2

Creating a Basic Pivot Table

The action of updating your pivot cache by taking another snapshot of your data source is called refreshing your data. There are two reasons you may have to refresh your pivot table report: ■

Changes have been made to your existing data source.



Your data source’s range has been expanded with the addition of rows or columns.

These two scenarios are handled in different ways.

Changes Have Been Made to Your Existing Data Source

NOTE

If a few cells in your pivot table’s source data have changed due to edits or updates, your pivot table report can be refreshed with a few clicks. Simply right-click inside your pivot table report and select Refresh Data. This selection takes another snapshot of your dataset, overwriting your previous pivot cache with the latest data.

You can also refresh the data in your pivot table by selecting the Options group from the PivotTable Tools tab and then choosing Refresh.

TIP

2

Clicking anywhere inside your pivot table activates the PivotTable Tools tab just above the main Ribbon.

Your Data Source’s Range Has Been Expanded with the Addition of Rows or Columns When changes have been made to your data source that affect its range (for example, you’ve added rows or columns), you have to update the range being captured by the pivot cache. To do this, click anywhere inside your pivot table and then select Options from the PivotTable Tools tab. From here, select Change PivotTable Data Source. This selection triggers the dialog box shown in Figure 2.25. All you have to do here is update the range to include new rows and columns. After you have specified the appropriate range, click the OK button.

Sharing the Pivot Cache

41

Figure 2.25 The Change PivotTable Data Source dialog box enables you to redefine the source data for your pivot table.

Sharing the Pivot Cache Many times, you may have to analyze the same dataset in multiple ways. In most cases, this process requires you to create separate pivot tables from the same data source. You might remember that each time you create a pivot table, you are storing a snapshot of your entire dataset in a pivot cache. Every pivot cache that is created increases your memory usage and file size. Because of this increase in file size, you should consider sharing your pivot cache. That is, in those situations in which you need to create multiple pivot tables from the same data source, use the same pivot cache to feed multiple pivot tables. By using the same pivot cache for multiple pivot tables, you gain a certain level of efficiency when it comes to memory usage and files size. In previous versions of Excel, when you created a pivot table using a dataset already being used in another pivot table, Excel actually gave you the option of using the same pivot cache. In Excel 2007, Excel gives you no such option. Each time you create a new pivot table in Excel 2007, a new pivot cache is automatically created even though one may already exist for the dataset being used. The side effect of this behavior is that your spreadsheet bloats with redundant data each time you create a new pivot table using the same dataset. You can easily work around this potential problem by employing copy and paste. That’s right. By simply copying a pivot table and pasting it somewhere else, you create another pivot table, without duplicating the pivot cache. This allows you to link as many pivot tables as you want to the same pivot cache, with a negligible increase in memory and file size.

Side Effects of Sharing a Pivot Cache It’s important to note that there are a few side effects to sharing a pivot cache. For example, suppose you have two pivot tables using the same pivot cache. Certain actions affect both pivot tables. They include ■

Refreshing Your Data—You cannot refresh one pivot table and not the other. Refreshing affects both tables.



Adding a Calculated Field—If you create a calculated field in one pivot table, your newly created calculated field shows up in the other pivot table’s field list.



Adding a Calculated Item—If you create a calculated item in one pivot table, it shows in the other as well.

2

42

Chapter 2

Creating a Basic Pivot Table



Grouping or Ungrouping Fields—Any grouping or ungrouping you perform affects both pivot tables. For instance, suppose you group a date field in one pivot table to show months. The same date field in the other pivot table is also grouped to show months.

Although none of these side effects are critical flaws in the concept of sharing a pivot cache, it is important to keep them in mind when determining if using a pivot table as your data source is the best option for your situation.

2

Saving Time with New Pivot Table Tools Microsoft has invested a lot of time and effort in the overall pivot table experience. The results of these efforts are tools that make pivot table functionality more accessible and easier to use. Let’s take a moment to look at a few of the tools that help you save time when managing your pivot tables.

Deferring Layout Updates The frustrating part of building a pivot table from a large data source is that each time you add a field to a pivot area, you are left waiting while Excel crunches through all that data. This can become a maddeningly time-consuming process if you have to add several fields to your pivot table. Excel 2007 offers some relief for this problem by providing a way to defer layout changes until you are ready to apply them. You can activate this option by clicking the relatively inconspicuous Defer Layout Update check box on the PivotTable Field List dialog box, as shown in Figure 2.26.

NOTE

Here’s how this feature works. When you place a check in the Defer Layout Update check box, you prevent your pivot table from making real-time updates as you move your fields around without your pivot table. In Figure 2.26, notice that fields in the drop zones are not in the pivot table yet. The reason is that the Defer Layout Update check box is active. When you are ready to apply your changes, simply click the Update button on the lowerright corner of the PivotTable Field List dialog box.

Remember to remove the check from the Defer Layout Update check box when you are done building your pivot table. Leaving it checked results in your pivot table remaining in a state of manual updates, preventing you from using the other features of the pivot table (that is, sorting, filtering, grouping).

Starting Over with One Click Often you might want to start from scratch when working with your pivot table layouts. Excel 2007 provides a simple way to essentially start over without deleting your pivot cache. Select Options under the PivotTable Tools tab and select the Clear dropdown.

Saving Time with New Pivot Table Tools

43

Figure 2.26 Click the Defer Layout Update check box to prevent your pivot table from updating while you add fields.

2

As you can see in Figure 2.27, this command allows you to either clear your entire pivot table layout or remove any existing filters you may have applied in your pivot table.

Figure 2.27 The Clear command allows you to clear your pivot table fields or remove the applied filters in your pivot table.

Relocating Your Pivot Table You may find that, after you have created your pivot table, you need to move it to another location. It may be in the way of other analyses on the worksheet, or you may simply need to move it to another worksheet. Although there are several ways to move your pivot table, Excel 2007 provides a no-frills way to easily change the location of your pivot table.

44

Chapter 2

Creating a Basic Pivot Table

Select Options under the PivotTable Tools tab and select Move PivotTable. This icon activates the Move PivotTable dialog box illustrated in Figure 2.28. All you have to do here is specify where you want your pivot table moved.

Figure 2.28 The Move PivotTable dialog box allows you to quickly move your pivot table to another location.

2

Next Steps In the next chapter, you learn how to enhance your pivot table reports by customizing your fields, changing field names, changing summary calculations, applying formats to data fields, adding and removing subtotals, and using the Show As setting.

Customizing a Pivot Table Although pivot tables provide an extremely fast way to summarize data, sometimes the pivot table defaults aren’t exactly what you need. You can use many powerful settings to tweak the information in your pivot table. These tweaks range from making cosmetic changes to changing the underlying calculation used in the pivot table. In Excel 2007, controls to customize the pivot table are found in a myriad of places: the Options ribbon, the Design ribbon, the Field Settings dialog box, the Data Field Settings dialog box, the PivotTable Options dialog box, and context menus. Rather than cover each set of controls sequentially, this chapter seeks to cover functional areas in customizing pivot table customization: ■

Minor Cosmetic Changes—Changing blanks to zeros, adjusting the number format, renaming a field. Although these changes are minor, they are annoying and affect almost every pivot table that you create.



Layout Changes—Comparing three possible layouts, showing/hiding subtotals and totals.



Major Cosmetic Changes—Using table styles to quickly format your table.



Summary Calculation—Changing from Sum to Count, Min, Max, and more. If you have a table that defaults to Count of Revenue instead of Sum of Revenue, you need to visit this section.



Advanced Calculation—Using settings to show data as a running total, % of total, and more.



Other Options—Quickly reviewing more obscure options found throughout the Excel interface.

3 IN THIS CHAPTER Making Common Cosmetic Changes . . . . . . . .46 Making Layout Changes . . . . . . . . . . . . . . . . . .52 Case Study: Converting a Pivot Table to Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56 Customizing the Pivot Table Appearance with Styles and Themes . . . . . . . . . . . . . . . . . .61 Changing Summary Calculations . . . . . . . . . . .65 Adding and Removing Subtotals . . . . . . . . . . .68 Using Running Total Options . . . . . . . . . . . . . .70 Case Study: Producing Revenue by Line of Business Report . . . . . . . . . . . . . . . . . . . . . . . . .77 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81

46

Chapter 3

Customizing a Pivot Table

Making Common Cosmetic Changes A few changes need to be made to almost every pivot table. These changes make your pivot table easier to understand and interpret. Figure 3.1 shows a typical pivot table. This pivot table has two fields in the Row Labels area and one field in the Column Labels area.

Figure 3.1 A default pivot table.

3

This pivot table contains several annoying items that you might want to change quickly: ■

The default table style uses no gridlines. This makes it difficult to follow the rows and columns across.



Numbers in the values area are in a general number format. There are no commas, currency symbols, and so on.



For sparse datasets, there are many blanks in the values area. The blank cell in B6 indicates that there were no sales in Denver for branch 101313. Most people would prefer to see a zero instead of blanks.



Excel renames fields in the values area with the unimaginative name Sum of Revenue. You can change this name.

You can correct each of these annoyances with just a few mouse clicks. The following sections address each issue.

Making Common Cosmetic Changes

47

Applying a Table Style to Restore Gridlines The default pivot table layout contains no gridlines. This format is annoying and a giant step backward. Luckily, you can easily apply a table style. Any table style that you choose will be better than the default. Follow these steps to apply a table style:

1. Make sure that the active cell is in the pivot table. 2. From the Ribbon, choose the Design tab. 3. Three arrows appear at the right side of the PivotTable Style gallery. Click the bottom arrow to open the complete gallery, as shown in Figure 3.2.

4. Choose any style other than the first style from the drop-down. Styles toward the bottom of the gallery tend to have more formatting.

Figure 3.2 The gallery contains 75 styles to choose from.

It doesn’t matter which style you choose from the gallery; any of the 74 other styles are better than the default style.

➔ For more details about customizing styles,see“ Customizing the Pivot Table Appearance with Styles and Themes,”p. 61.

Changing the Number Format to Add Thousands Separators If you’ve gone to the trouble of formatting your underlying data, you might expect that the pivot table would capture some of this formatting. Unfortunately, it does not. Even if your underlying data fields were formatted with a certain numeric format, the default pivot table presents values formatted with a general format. For example, in the figures in this chapter, the numbers are in the hundreds of thousands. At this level of sales, you would normally have a thousands separator and probably no decimal places. Although the original data had a numeric format applied, the pivot table routinely formats your numbers in an ugly general style.

3

48

Chapter 3

Customizing a Pivot Table

You access the numeric format for a field in the Data Field Settings dialog box. There are four ways to display this dialog box: ■

Right-click a number in the values area of the pivot table and choose Value Field Settings.



Double-click the Sum of Revenue cell in cell A3 of Figure 3.3.



Click the drop-down arrow on the Sum of Revenue field in the drop zones of the PivotTable Field List. Then choose Field Settings from the context menu.



Select any cell in the values area of the pivot table. From the Options ribbon, choose Field Settings from the Active Field group.

As shown in Figure 3.3, the Data Field Settings dialog box is displayed. To change the numeric format, click the Number Format button in the lower-left corner.

Figure 3.3 Display the Data Field Settings dialog box and then click Number Format.

In the Format Cells dialog box, you can choose any built-in number format or choose a custom format. The custom number format shown in Figure 3.4 displays numbers in thousands with a K abbreviation after the number.

NOTE

3

Although Excel 2007 offers a Live Preview feature for many dialog boxes, the Format Cells dialog box does not offer one.You must assign the number format and then click OK twice to see the changes.

Making Common Cosmetic Changes

49

Figure 3.4 Choose an easier-to-read number format from the Format Cells dialog box.

3

Replacing Blanks with Zeros One of the elements of good spreadsheet design is that you should never leave blank cells in a numeric section of the worksheet. Even Microsoft believes in this rule; if your source data for a pivot table contains 1 million numeric cells and 1 blank cell, Excel 2007 treats the entire column as if it were text. This is why it is incredibly annoying that the default setting for a pivot table leaves many blanks in the values area of some pivot tables. The blank tells you that there were no sales for that particular combination of labels. In the default view, an actual zero is used to indicate that there was activity, but the total sales were zero. This value might mean that a customer bought something and then returned it, resulting in net sales of zero. Although there are limited applications in which you would want to differentiate between having no sales and having net zero sales, this seems rare. In 99% of the cases, you should fill in the blank cells with zeros. Follow these steps to change this setting for the current pivot table:

1. Select a cell inside the pivot table. 2. On the Options ribbon, choose the Options icon from the Pivot Table Options group to display the PivotTable Options dialog box.

3. On the Layout & Format tab, in the Format section, type 0 next to the field labeled For Empty Cells Show (see Figure 3.5).

4. Click OK to accept the change.

50

Chapter 3

Customizing a Pivot Table

Figure 3.5 Enter a zero here to replace the blank cells with zero.

3 Enter a zero here

The result is that the pivot table is filled with zeros instead of blanks, as shown in Figure 3.6.

Figure 3.6 Your report is now a solid contiguous block of nonblank cells.

Making Common Cosmetic Changes

51

Changing a Field Name Every field in the final pivot table has a name. Fields in the row, column, and filter areas inherit their names from the heading in the source data. Fields in the data section are given names such as Sum of Revenue. In some instances, you may prefer to print a different name in the pivot table. You might prefer Total Revenue instead of the default name. In these situations, the capability to change your field names comes in quite handy. Although many of the names are inherited from headings in the original dataset, when your data is from an external data source, you might not have control over field names. In these cases, you might want to change the names of the fields as well. To change a field name in the values area, follow these steps:

1. Select a cell in the pivot table that contains the appropriate value. In Figure 3.7, the values area contains both hours and revenue. If you want to rename Sum of Revenue, select any cell from B5:B24.

2. On the Options ribbon, select the Field Settings icon from the Active Field group. 3. In the Data Field Settings dialog box, type a new name in the Custom Name field. You can enter any unique name you like. One common frustration occurs when you would like to rename Sum of Revenue to Revenue. The problem is that this name is not allowed because it is not unique; you already have a Revenue field in the source data. To work around this limitation, you can name the field and add a space to the end of the name. Excel considers “Revenue” (with a space) to be different from “Revenue” (with no space). Because this change is cosmetic, the readers of your spreadsheet will not notice the space after the name. The new name appears in the pivot table. Now look at cell B5 in Figure 3.7. The name Revenue (with a space) is less awkward than the default Sum of Revenue.

Figure 3.7 The name typed in the Custom Name box appears in the pivot table. Although names should be unique, you can trick Excel into accepting a similar name by adding a space to the end of it.

3

Chapter 3

Customizing a Pivot Table

TIP

52

If you rename a field in the row, column, or filter areas, the dialog box that opens in response to Field Settings is called Field Settings instead of Data Field Settings.This dialog box has different options, but the Custom Name field is located in the same place as shown in Figure 3.7.

Making Layout Changes Excel 2007 offers three layout styles instead of the two styles available in previous versions of Excel. The new style—Compact Layout—is promoted to be the default layout for your pivot tables. Layout changes are controlled in the Layout group of the Design ribbon, as shown in Figure 3.8. This group offers four icons:

3



Subtotals—Moves subtotals to the top or bottom of each group, or turns them off.



Grand Totals—Turns the grand totals on or off for rows and columns.



Report Layout—Uses the Compact, Outline, or Tabular forms.



Blank Rows—Inserts or removes blank lines after each group.

Figure 3.8 The Layout group on the Design ribbon offers different layouts and options for totals.

Using the New Compact Layout By default, all new pivot tables use the compact layout shown in Figure 3.6. In this layout, multiple fields in the row area are stacked up in column A. Note in the figure that the Denver market and Midwest region are both in column A. The compact form is suited for using the Expand and Collapse icons. Select one of the market cells—A7 as an example—and click the Collapse Entire Field icon on the Options ribbon. Excel hides all the detail below this field and shows only the regions, as shown in Figure 3.9.

Making Layout Changes

53

Collapse icon

Figure 3.9 Click the Collapse Entire Field icon to hide levels of detail.

Plus icon

TIP

After a field is collapsed, you can show detail for individual regions by using the plus icons in column A, or you can click Expand Entire Field on the Options ribbon to see the detail again.

Figure 3.10 When you attempt to expand the innermost field, Excel offers to add a new innermost field.

If you select a cell in the innermost row field and click Expand Entire Field, Excel displays the Show Detail dialog box, as shown in Figure 3.10, to allow you to add a new innermost row field.

3

54

Chapter 3

Customizing a Pivot Table

Using the Outline Form Layout When you select Design, Layout, Report Layout, Show in Outline Form, Excel fills column A with the outermost row field. Additional row fields occupy columns B, C, and so on. Figure 3.11 shows the pivot table in Outline form.

Figure 3.11 The Outline layout puts each row field in a separate column.

3

This layout is better suited if you plan to copy the values from the pivot table to a new location for further analysis. Although the Compact layout offers a clever approach by squeezing multiple fields in one column, it is not ideal for reusing the data later. By default, both the Compact and Outline layouts put the subtotals at the top of each group. You can use the Subtotals drop-down on the Design ribbon to move the totals to the bottom of each group, as shown in Figure 3.12.

Using the Traditional Tabular Layout Pivot table veterans will recognize the tabular layout shown in Figure 3.13. This layout is similar to the one that has been used in pivot tables since their invention. In this layout, the subtotals can never appear at the top of the group.

Making Layout Changes

55

Figure 3.12 With subtotals at the bottom of each group, the pivot table occupies several more rows.

3

The tabular layout is probably the best layout if you hope to later use the resulting summary data in a subsequent analysis.

56

Chapter 3

Customizing a Pivot Table

Figure 3.13 The tabular layout is similar to pivot tables in prior versions of Excel.

3

C A S E S T U DY

Converting a Pivot Table to Values Say that you want to summarize your dataset to show sales by Region, Market, and Quarter.Your goal is to export this data for use by another system. The result in Figure 3.13 is close to the desired output, with a few exceptions: ■

The subtotals in rows 9, 14, 19, and 23 should be removed.



The blank cells in A7:A8, A11:A13, A16:A18, and A21:A22 should be filled in.



The grand total should be removed from row 24 and column G.



The pivot table should be converted from a live pivot table to static values.

To make these changes, follow these steps: 1. Select any cell in the pivot table. 2. From the Design ribbon, choose Grand Totals, Off for Rows and Columns.

Converting a Pivot Table to Values

57

3. Select Design, Subtotals, Do Not Show Subtotals. 4. Select A5:F19, as shown in Figure 3.14. Figure 3.14 After removing the total and subtotal information, select the data and one row of headings.

3

5. Press Ctrl+C to copy the data from the pivot table. 6. In a blank section of the workbook, choose Home, Clipboard, Paste, Paste Values to make a static copy of the data. The final step is filling in the blank cells in the first column of the table. 7. Select column A of the dataset. 8. In the Editing group of the Home ribbon, choose the Find & Select drop-down and then choose Go To Special. 9. In the Go To Special dialog box, as shown in Figure 3.15, select Blanks and click OK. 10. Type the equal sign (=), press the up-arrow key, and then press Ctrl+Enter to accept this formula for all the blank cells.This combination enters a formula in which each blank cell inherits the value from the cell above it, as shown in Figure 3.16.

CAUTION If you attempt to choose Copy and then Paste Values, Excel complains that you cannot use this command on nonadjacent cells. Instead, follow steps 11–13.

11. Reselect the cells in column A. 12. Click the Copy icon in the Clipboard group on the Home ribbon. 13. Choose Paste Values from the Paste drop-down on the Home ribbon.

58

Chapter 3

Customizing a Pivot Table

Figure 3.15 Choosing Blanks from the Go To Special dialog box selects only the blank cells in column A.

3

Figure 3.16 The last step is changing the formulas in column A to values.

The result is a solid block of summary data, as shown in Figure 3.17.These 90 cells are a summary of the 1.1 million cells in the original dataset, but they also are suitable for exporting to other systems.

Converting a Pivot Table to Values

59

Figure 3.17 The final dataset is suitable for exporting to another system.

3

Controlling Blank Lines, Grand Totals, Subtotals, and Other Settings Additional settings in the pivot table allow you to toggle various elements. Subtotals can be moved to the top or bottom of the group or turned off entirely. As noted previously, moving the subtotals to the top of the group saves a few rows in the pivot table. However, top subtotals are available only when the layout is set to Compact or Outline. Use the Subtotals icon on the Design ribbon to choose the subtotals option. Figure 3.18 shows the subtotals at the top of each group. Grand totals can appear at the bottom of each column and/or at the end of each row, or they can be turned off altogether. Settings for grand totals appear in the Grand Totals dropdown of the Layout group on the Design ribbon. The wording in this drop-down seems just a bit confusing. If you would like a grand total column on the right side of the table, you need to select On for Rows only. Even though it is a grand total column, each total is totaling a single row. Similarly, to add a grand total row, you need to select On for Rows Columns only. Each individual grand total in the total row is totaling the cells in a column. In Figure 3.18, the grand total column appears because the Grand Totals drop-down is set to On For Rows Only. The Blank Rows drop-down allows you to insert blank lines between groups. In Figure 3.18, the blank lines in rows 13, 19, and 25 appear because Insert Blank Line After Each Item was selected in the Blank Rows drop-down.

60

Chapter 3

Customizing a Pivot Table

Figure 3.18 Subtotals at the top, grand totals for the rows, and blank lines between groups are controlled through icons in the Layout group on the Design ribbon.

3

As you examine the pivot table in Figure 3.18, you might think the area around B8:B9 appears strange. Whereas the sales figures for columns C, D, and E are closely aligned with the headings, the Qtr1 heading in B8 appears far away from the sales figures in B9:B29. This happens because all the headings in B8:E8 are left-aligned. Something is causing column B to be too wide. That something is the text Column Labels in B7. This text, plus Row Labels in A8, is a new feature in Excel 2007. Although this feature might have been designed to improve readability, it is annoying that the text makes column B too wide. To remove these text entries, click the Field Headers icon in the Show/Hide group on the Options ribbon. This group also has icons to turn off the plus and minus buttons or to hide the PivotTable Field List. Figure 3.19 shows this section of the Ribbon, as well as the pivot table with all three items turned off.

Customizing the Pivot Table Appearance with Styles and Themes

61

Show/Hide Group

Figure 3.19 In Excel 2007, field headers serve little purpose.

Customizing the Pivot Table Appearance with Styles and Themes The PivotTable Styles gallery on the Design ribbon offers 84 built-in styles. Grouped into 28 styles each of Light, Medium, and Dark, the gallery offers variations on the accent colors used in the current theme. Note that you can modify the thumbnails for the 84 styles shown in the gallery by using the four check boxes in the PivotTable Style Options group. In Figure 3.20, the 84 styles are shown with all four of the option buttons unchecked. In Figure 3.21, the 84 styles are shown with accents for row headers, column headers, and alternating colors in the columns.

TIP

The PivotTable Style Options group appears to the left of the PivotTable Styles gallery. If you want banded rows or columns, it is best to choose this option before opening the gallery. Some of the 84 themes do not support banded columns or banded rows.

By checking the Banded Columns check box prior to opening the gallery, you can see which styles support the banded columns. If the Banded Columns or Rows check box is selected and the thumbnail in the gallery does not show the effect, you know to avoid that style.

Excel 2007’s Live Preview feature works in the styles gallery. As you hover your mouse cursor over style thumbnails, the worksheet shows a preview of the style.

3

62

Chapter 3

Customizing a Pivot Table

Figure 3.20 The 84 thumbnails appear one way when no style options are checked.

3

Figure 3.21 The 84 thumbnails appear differently with three style options checked.You can see that many of the styles do not support banded columns, even though this option is chosen.

Customizing a Style You can create your own pivot table styles. The new styles are added to the gallery and will be available on every new pivot table created on your computer. Say that you want to create a pivot table style in which the banded colors are two rows high. Follow these steps to create the new style:

Customizing the Pivot Table Appearance with Styles and Themes

63

1. Find an existing style in the PivotTable Styles gallery that supports banded rows. Rightclick the style in the gallery and choose Duplicate. Excel displays the Modify Table Quick Style dialog box.

2. Choose a new name for the style. Excel initially appends a 2 to the existing style name, so you have a name like PivotStyleMedium16 2.

3. In the Table Element list, click on First Row Stripe. A new section called Stripe Size appears in the dialog box.

4. Choose 2 from the Stripe Size drop-down, as shown in Figure 3.22. Figure 3.22 Customize the style in the Modify Table Quick Style dialog box.

3

5. If you want to change the stripe color, click the Format button. The Format Cells dialog box appears. Here, click the Fill tab and then choose a fill color. Click OK to accept the color and return to the Modify Table Quick Style dialog box.

6. In the Table Element List, click on Second Row Stripe. Change the Stripe Size dropdown to 2.

7. Click OK. Prepare to be disappointed that the change didn’t work. It’s okay, though. When you modified table style Medium 16, you actually created a brand new style. The pivot table is still formatted in the original style.

8. Open the PivotTable Styles gallery. Your new style is added to the top of the gallery in the Custom section. Choose the style to apply the formatting, as shown in Figure 3.23.

64

Chapter 3

Customizing a Pivot Table

Figure 3.23 Your new style is available at the top of the gallery.

Choosing a Default Style for Future Pivot Tables

In the PivotTable Styles gallery on the Design ribbon, right-click the style and choose Set as Default.

Modifying Styles with Document Themes The formatting options for pivot tables in Excel 2007 are impressive. The 84 styles, combined with 8 combinations of the Style options, make for hundreds of possible format combinations. In case you ever become tired of these combinations, you can visit the Themes drop-down on the Page Layout ribbon. Twenty built-in themes are available here. Each theme has a new combination of accent colors, fonts, and shape effects. Choosing a new theme affects the fonts and colors in your pivot table styles. To change a document theme, open the Themes drop-down on the Page Layout ribbon. As you hover the mouse cursor over the themes in the drop-down, Live Preview shows you the colors and fonts in your table, as shown in Figure 3.24. To select a theme, click on it.

CAUTION Changing the theme affects the entire workbook. It changes the colors, fonts, and effects of all charts, shapes, tables, and pivot tables on all worksheets of the active workbook.

TIP

3

You can control which style is the default style to use for all future pivot tables on the computer. The default can either be one of the built-in styles or a new custom style that you modified.

Some of the themes have contemporary fonts.You can apply the colors from a new theme without changing the fonts in your document by using the Colors drop-down in the Themes group on the Page Layout ribbon.

Changing Summary Calculations

65

Figure 3.24 Choose a document theme to modify the colors and fonts in the built-in styles.

3

Changing Summary Calculations When creating your pivot table report, Excel , by default, summarizes your data by either counting or summing the items. Instead of Sum or Count, you might want to choose functions such as Min, Max, and Count Numeric. In all, 11 options are available. However, the common reason to change a summary calculation is that Excel incorrectly chose to count instead of sum your data.

Understanding Why One Blank Cell Causes a Count If all the cells in a column contain numeric data, Excel chooses to sum. If just one cell is either blank or contains text, Excel chooses to count. In Figure 3.25, the worksheet contains more than 60,000 numeric entries in column N and a single blank cell in N2. The one blank cell is enough to cause Excel to count the data instead of summing. In Excel 2007, the first clue that you have a problem appears when you click the check box for Revenue in the Fields section of the PivotTable Field List. If Excel moves the Revenue field to the Row Labels drop zone, you know that Excel considers the field to be text instead of numeric.

66

Chapter 3

Customizing a Pivot Table

Figure 3.25 The single blank cell in N2 causes problems in the default pivot table.

3

Be vigilant while dragging fields into the Values drop zone. If a calculation appears to be dramatically too low, check to see whether the field name reads Count of Revenue instead of Sum of Revenue. When you created the pivot table in Figure 3.26, you should have noticed that your company had only $68,613 in revenue instead of $10 million. This should be a hint to notice that the heading in B3 reads Count of Revenue instead of Sum of Revenue. In fact, 68,613 is the number of records in the dataset.

Figure 3.26 Your revenue numbers look anemic. Notice in cell B3 that Excel chose to count instead of sum the revenue.This often happens if you inadvertently have one blank cell in your Revenue column.

You can easily override the incorrect Count calculation. Activate the Data Field Settings dialog box by double-clicking on Count of Revenue and then change the Summarize Value Field By setting from Count to Sum, as shown in Figure 3.27.

Using Functions Other Than Count or Sum Excel offers a total of 11 functions in the Summarize By section of the PivotTable Field dialog box. The options available are as follows: ■

Sum—Provides a total of all numeric data.



Count—Counts all cells, including numeric, text, and error cells. This is equivalent to the Excel function =COUNTA().



Average—Provides an average. Figure 3.28 shows a report detailing average sales per region and product line. An analyst might wonder why the average housekeeping sale in the West is $152 higher than in the Midwest.

Changing Summary Calculations

67

Figure 3.27 Change the function from Count to Sum in the Data Field Settings dialog box.

3

Figure 3.28 Average sales per region and product line.



Max—Shows the largest value.



Min—Shows the smallest value.



Product—Multiplies all the cells together. For example, if your dataset has cells with values of 3, 4, and 5, the product would be 60.



Count Nums—Counts only the numeric cells. This is equivalent to the Excel function =COUNT().



StdDev and StdDevP—Calculate the standard deviation. Use StdDevP if your dataset contains the complete population. Use StdDev if your dataset contains a sample of the population. Figure 3.29 shows the results of two tests. Although the students averaged 87% on both tests, the math test had a higher standard deviation. Standard deviations explain how tightly results are grouped around the mean.



Var and VarP—Calculate the statistical variance. Use VarP if your data contains a complete population. If your data contains only a sampling of the complete population, use Var to estimate the variance.

68

Chapter 3

Customizing a Pivot Table

Figure 3.29 A low standard deviation on the science test means that all the students understand the concepts equally well. A higher standard deviation on the math test indicates that student scores were spread over a wider range.

Adding and Removing Subtotals 3

Subtotals are undeniably an essential feature of pivot table reporting. Sometimes you may want to suppress the display of subtotals, and other times you may want to show more than one subtotal per field.

Suppress Subtotals When You Have Many Row Fields When you have many row fields in your report, subtotals can mire your view. Take the example in Figure 3.30. You might want to suppress the subtotals for the Market and Product Line fields.

Figure 3.30 Sometimes you don’t need subtotals at every level.

To remove subtotals for the Product Line field, click on the Product Line field in the drop zone section of the PivotTable Field List. Choose Field Settings. In the Field Settings dialog box, choose None under Subtotals, as shown in Figure 3.31. Repeat this step for other row fields. After repeating these steps for Market, you’ll find the report in Figure 3.32 to be much easier on the eyes.

Adding and Removing Subtotals

69

Figure 3.31 Choose None to remove subtotals at the Product Line level.

3

Figure 3.32

TIP

After specifying None for two fields, you give the report a cleaner look.

If you want to suppress the subtotals for all the row fields, it is easier to choose Design, Layout, Subtotals, Do Not Show Subtotals.

Adding Multiple Subtotals for One Field You can add customized subtotals to a row or column label field. Select the Region field in the drop zone of the PivotTable Field List and choose Field Settings.

70

Chapter 3

Customizing a Pivot Table

In the Field Settings dialog box, choose Custom and select the types of subtotals you would like to see. The dialog box in Figure 3.33 shows five subtotals selected for the Region field.

Figure 3.33 By selecting the Custom option in the Subtotals section, you can specify multiple subtotals for one field.

3

Using Running Total Options So far, every pivot table created has used the Normal option. When you want to create running totals or compare an item to another item, you have eight choices other than Normal. The nine options are on the second tab of the Data Field Settings dialog box. To access them, follow these steps:

1. Select a cell in the values area of your pivot table. Or, select the Sum of Revenue cell. 2. On the Options ribbon, click the Field Settings icon in the Active Group field. 3. Click the Show Values As tab in the Data Field Settings dialog box. Initially, the Show Values As drop-down is set to Normal, and the Base Field and Base Item list boxes are grayed out, as shown in Figure 3.34. The capability to create custom calculations is another example of the unique flexibility of pivot table reports. With the Show Data As setting, you can change the calculation for a particular data field to be based on other cells in the values area. When you click the Show Values As drop-down, you have eight choices other than Normal. The choices are ■

% of Row—Shows percentages that total across the pivot table to 100%.



% of Column—Shows percentages that total up and down the pivot table to 100%.



% of Total—Shows percentages such that all the detail cells in the pivot table total to 100%.



Difference From—Shows the difference of one item compared to another item or to the previous item.

Using Running Total Options



% of—Expresses the values for one item as a percentage of another item.



% Difference From—Expresses the percentage change from one item to another item.



Running Total In—Calculates a running total.



Index—Calculates the relative importance of items.

71

The following sections illustrate a number of these options.

Figure 3.34 Access the second tab of the Data Field Settings dialog box to see the running total options.

3

Display Change from Year to Year with Difference From Companies always want to know how they are doing this month compared to last month. Or, if their business is seasonal, they want to know how they are doing this month versus the same month of last year. To set up such a report, double-click the Sum of Revenue field and click the Show Values As tab. In the Show Data As drop-down list, select Difference From. Because you want to compare one year to another, select Years from the Base Field option. In the Base Item field are several viable options. If you always want to compare one year to the prior year, select the (Previous) option, as shown in Figure 3.35. If you have several years’ worth of data and want to always compare to a base year of 2007, you could select 2007. Figure 3.35 shows both the dialog box settings and the report that results from the settings. The report shows that January 2008 revenue was $55K higher than the same month in 2007.

72

Chapter 3

Customizing a Pivot Table

Figure 3.35 The Difference From option allows you to compare two different time periods.

NOTE

3

When you use an option from the Show Data As drop-down list, Excel does not change the headings in any way to indicate that the data is in something other than normal view. It is helpful to manually add a title above the pivot table to inform the readers what they are looking at.

Compare One Year to a Prior Year with % Difference From The % Difference From option is similar to Difference From. This option displays the change as a percentage of the base item. In Figure 3.36, the report shows 2008 as a percentage change from 2007.

Track YTD Numbers with Running Total In If you need to compare a year-to-date (YTD) total revenue by month, you can do so with the Running Total In option. In Figure 3.37, the Revenue field is set up to show a Running Total In with a base field of Invoice Date. With this report, you can see that the company earned a total of $2.6 million through March 2007.

Determine How Much Each Line of Business Contributes to the Total The head of the company is often interested in what percentage of the revenue each division of the company is contributing. You can use the % of Row option, as in Figure 3.38, to show such a report. Each row totals to 100%. You can see that Maintenance contributed 70.97% of the revenue in February, but only 59.82% in December.

Using Running Total Options

73

Figure 3.36 The % Difference From option shows that revenue from January 2008 is up 8.02% over January 2007.

3

Figure 3.37 The Running Total In option is great for calculating YTD totals.

Create Seasonality Reports A seasonality report is great for seeing the seasonality of your business. The % of Column option produces percentages that total to 100% in each column. Figure 3.39 shows a report in which Jan+Feb+Mar+…+Dec add to 100% for each year.

Measure Percentage for Two Fields with % of Total The option % of Total can be used for a myriad of reports. Figure 3.40 shows a report by Region and Product Line. The values in each cell show the percentage of revenue contribution from that region and line. Cell F8 shows that sales from Maintenance account for 66.53% of the total revenue. The South region’s sales of Maintenance account for 21.95% of total sales.

74

Chapter 3

Customizing a Pivot Table

Figure 3.38 The % of Row option produces percentages that total to 100% in each row.

3

Figure 3.39 The % of Column option produces percentages that total to 100% in each column.This option is great for measuring seasonality.

Using Running Total Options

75

Figure 3.40 The % of Total option produces a report in which every cell is a percentage of total sales. The manager of the South Region Maintenance department can use this report to explain why his department should get a raise this year.

3

Compare One Line to Another Line Using % Of The % Of option allows you to compare one item to another item. This comparison might be relevant if you believe that housekeeping and landscaping should be related. You can set up a pivot table that compares each product line to landscaping revenue. The result is shown in Figure 3.41.

Track Relative Importance with the Index Option The final option, Index, creates a fairly obscure calculation. Microsoft claims that this calculation describes the relative importance of a cell within a column. Look at the normal data at the top of Figure 3.42. To calculate the index for Georgia Peaches, Excel first calculates Georgia Peaches x Grand Total Sales. This would be $180 x $848. Next, Excel calculates Georgia Sales x Peach Sales. This would be $210 x $290. It then divides the first result by the second result to come up with a relative importance index of 2.51.

76

Chapter 3

Customizing a Pivot Table

Figure 3.41 This report is created using the % Of option with Landscaping as the base item.

3

Figure 3.42 Using the Index function, Excel shows that peach sales are more important in Georgia than in Tennessee.

Producing Revenue by Line of Business Report

77

The index report is shown at the bottom of Figure 3.42. Excel explains that peaches are more important to Georgia (with an index of 2.51) than they are to California (with an index of 0.49). Even though Georgia sold more apples than Tennessee, apples are more important to Tennessee (index of 1.51) than to Georgia (index of 0.34). Relatively, an apple shortage will cause more problems in Tennessee than in Georgia.

C A S E S T U DY

Producing Revenue by Line of Business Report You have been asked to produce a report that provides a comprehensive look at revenue by product line.This analysis needs to include revenue dollars by product line for each market, the percent of revenue that each product line represents within the markets, and the percent total company dollars that each market represents within the product lines. Here are the steps to follow: 1. Place your cursor inside your data source. Choose the Insert ribbon and then click the Pivot Table icon. 2. When the Create PivotTable dialog box appears, simply choose OK. A new worksheet is created with the beginnings of a pivot table report and the PivotTable Field List, as shown in Figure 3.43. Figure 3.43 After clicking OK, you get this blank pivot table report.

3

78

Chapter 3

Customizing a Pivot Table

3. Click the Market field in the fields section of the PivotTable Field List to automatically move Market to the Row Labels drop zone.Then drag the Product Line field into the Column Labels drop zone, as shown in Figure 3.44. Figure 3.44 Setting up the row and column fields.

3

4. Drag the Revenue field into the Values drop zone three times to create three separate revenue data items.There is a new Sum Values item in the Column Labels drop zone. Move this to the Row Labels drop zone, as shown in Figure 3.45. Figure 3.45 Having three copies of Sum of Revenue doesn’t look useful…yet.

5. In the Values drop zone, click on the first Sum of Revenue field and select Field Settings, as shown in Figure 3.46.

Producing Revenue by Line of Business Report

79

Figure 3.46 Use the drop-down in the Values drop zone to access Field Settings for a particular data field.

3

6. Change the name of the data field to Total Revenue, as shown in Figure 3.47. Then click the Number Format button to open the Format Cells dialog box. Change the format of the data item to Currency and then close both dialog boxes by clicking OK. Figure 3.47 Set up the first Revenue item as normal.

80

Chapter 3

Customizing a Pivot Table

7. Open the Data Field Settings for the Sum of Revenue2 field. 8. Change the name of the data field to Percent of Market. On the Show Values As tab, in the Show Values As drop-down, select the % of Row option. After you do that, choose the Number Format button to open the Format Cells dialog box. Change the format of the cells to Percentage, as shown in Figure 3.48. Close both dialog boxes by clicking OK twice. Figure 3.48 Use % of Row to get the Percentage of Market.

3

9. Open the Date Field Settings dialog box for Sum of Revenue3. 10. Change the name of the data field to Percent of Company. On the Show Values As tab, choose the % of Column option. After you do that, choose the Number button to open the Format Cells dialog box. Change the format of the cells to Percentage and then close both dialog boxes by clicking OK. As shown in Figure 3.49, your product line analysis is complete! You have the Total Revenue field, which gives you the revenue dollars by product line for each market.Then you have the Percent of Market field, which shows you the percent of revenue that each line represents within the markets. Finally, you have the Percent of Company field, which shows line of business revenue as a percentage of total company dollars.

Next Steps

81

Figure 3.49 The completed report shows three calculations for every data cell.

3

Next Steps Note that other pivot table customizations are covered in subsequent chapters: ■

Sorting a pivot table is covered in Chapter 4.



Filtering records in a pivot table is covered in Chapter 4.



Grouping daily dates up to months or years is covered in Chapter 4.



Adding new calculated fields is covered in Chapter 5.



Using data visualizations and conditional formatting in a pivot table is covered in Chapter 4.

In the next chapter, we discuss the filtering, sorting, and data visualization options available in Excel 2007. Using these tools is a great way to focus your pivot table on the largest drivers of success for your business.

This page intentionally left blank

Controlling the Way You View Your Pivot Data Microsoft added some excellent new features to Excel 2007’s pivot tables: ■





Whenever Mike or Bill entertained an audience with one of his seminars, they could be sure to “wow” the audience with obscure features like the Top 10 AutoShow feature that was buried four menus deep in prior versions of Excel. Microsoft has exposed the AutoSort and AutoShow options so that they are now just two clicks away from any pivot table. Grouping features go from being buried three levels deep in Excel 2003 to a button right on the Ribbon in Excel 2007. The Pivot Table Options dialog box has been expanded in Excel 2007.

4 IN THIS CHAPTER Grouping Pivot Fields . . . . . . . . . . . . . . . . . . . .83 Case Study: Creating an Order LeadTime Report . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 Case Study: Grouping Text Fields . . . . . . . . . . .90 Looking at the PivotTable Field List . . . . . . . .93 Sorting in a Pivot Table . . . . . . . . . . . . . . . . . . .96 Filtering the Pivot Table . . . . . . . . . . . . . . . . .102 Case Study: Creating a Top 10 Report . . . . . .113

This chapter covers grouping, sorting, filtering, data visualizations, and pivot table options.

Grouping Pivot Fields Although most of your summarization and calculation needs can be accomplished with standard pivot table settings, in special situations you might want your report to be summarized even further. For example, transactional data is typically stored with a transaction date. You commonly want to report this data by month, quarter, or year. The Group option allows you to quickly and easily consolidate transactional dates into a larger group such as month or quarter. Then you can summarize the data in those groups just as you would with any other field in your pivot table. As you learn in the next section, grouping is not limited to date fields. You can also group nondate fields to consolidate specific pivot items into a single item.

Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116

84

Chapter 4

Controlling the Way You View Your Pivot Data

Grouping Date Fields Figure 4.1 shows a pivot report by date. With two years’ worth of transactional data, the report spans 500+ columns. These 500 columns are a summary of the original 68,615 rows, but managers often want detail by month instead of detail by day.

Figure 4.1 When reported by day, the summary report spans 500+ columns. It would be meaningful to report by month, quarter, or year instead.

4

Excel makes it easy to group date fields. Select any date heading such as cell B4 in Figure 4.1. On the Options ribbon, click Group Field in the Group group.

Figure 4.2 Business users of Excel usually group by months, quarters, and years.

Grouping Pivot Fields

85

When your field contains date information, the Grouping dialog box appears. By default, the Months option is selected. You have choices to group by Seconds, Minutes, Hours, Days, Months, Quarters, and Years. It is possible and usually advisable to select more than one field in the Grouping dialog box. In this case, you want to select Months, Quarters, and Years, as shown in Figure 4.2. There are several interesting points to note about the resulting pivot table. First, notice that Quarters and Years have been added to your Field List. Don’t let this fool you. Your source data is not changed to include these new fields; instead, these fields are now part of your pivot cache in memory. Another interesting point to note is that, by default, the Years and Quarters fields are automatically added to the same area as the original date field in the pivot table layout, as shown in Figure 4.3.

Figure 4.3 By default, Excel adds the new grouped date fields to your pivot table layout.

4

86

Chapter 4

Controlling the Way You View Your Pivot Data

Including Years When Grouping by Months Although this point is not immediately obvious, it is important if you group a date field by month that you also include the year in the grouping. Examine the pivot table shown in Figure 4.4. This table has a date field that has been grouped by month and year. The months in column A use the generic abbreviations Jan, Feb, and so on. The sales for January 2007 are $339,689.

Figure 4.4 This table has a date field that is grouped by both month and year.

4

If, instead, you choose to group the date field only by month, Excel still continues to report the date field using the generic Jan abbreviation. The problem is that dates from January 2007 and January 2008 are both rolled up and reported together as “Jan.” Having a report that totals Jan 2007 and Jan 2008 might be useful only if you are performing a seasonality analysis. Under any other circumstance, the report of $681,865 in January sales is too ambiguous and is likely to be interpreted wrong. To avoid ambiguous reports like the one shown in Figure 4.5, always include a year in the Group dialog box when you are grouping by month.

Grouping Date Fields by Week The Grouping dialog box offers the choices to group by Second, Minute, Hour, Day, Month, Quarter, or Year. What if you need to group on a weekly or biweekly basis? This can be done. The first step is to find an actual paper calendar for the year in question. Your data might start on January 5, 2007, so it is helpful to know that January 5 was a Friday in that year. You are going to have to decide if weeks should start on Sunday or Monday or any other day. Check the paper calendar to learn that the nearest starting Monday is January 1, 2007.

Grouping Pivot Fields

87

Figure 4.5 If you fail to include the Year field in the grouping, the report mixes sales from Jan 2007 and Jan 2008 in the same number.

Select any date heading in your pivot table. Then choose Group Field from the Options ribbon. In the Grouping dialog box, unselect all the By options and choose only the Days field. This enables the spin button for Number of Days. To produce a report by week, increase the number of days from 1 to 7. Finally, you have to set up the Starting At date. If you were to accept the default of starting at January 5, 2007, all your weekly periods would run from Friday through Thursday. By checking a calendar before you begin, you know that you want the first group to start on January 1, 2007. Change this setting as shown in Figure 4.6.

Figure 4.6 The key to being able to access the Number of Days spin button is to select only Days from the By field.

4

88

Chapter 4

Controlling the Way You View Your Pivot Data

The result is a report showing sales by week, as shown in Figure 4.7.

Figure 4.7 You’ve produced a report showing sales by week.

CAUTION If you choose to group by week, none of the other grouping options can be selected.You cannot group this or any other field by month or quarter.

4

Grouping Two Date Fields in One Report When you group a date field by months and years, Excel repurposes the original date field to show months and adds a new field to show years. The new field is called Years. This is simple enough if you have only one date field in the report. If you need to produce a report that has two date fields, and you attempt to group both date fields by months and years, Excel arbitrarily names the first grouped field “Years” and the second grouped field “Years2.” This naming convention inevitably leads to confusion. In this case, it is important to rename the fields with a meaningful name.

C A S E S T U DY

Creating an Order Lead-Time Report The material schedulers at a manufacturing plant are usually concerned with the lead time from when an order arrives to when it needs to ship.The schedulers may know that it takes 60 business days to procure material, schedule production, and build the product. In a perfect world, if all their customers would order 61 or more days in advance, the manufacturing plant would not have to keep any excess raw material inventory on hand. But, in the real world, the plant always receives orders in which the customer wants the product faster. In these cases, the manufacturing plant may purchase extra inventory of the components with the longest lead time to accommodate rush orders.

Creating an Order Lead-Time Report

89

If your transactional data source includes a field for date shipped and another field for date ordered, you can easily produce a report showing the normal order lead time by product.This is a valuable report for the master schedulers in the manufacturing plant. Here are the steps to follow: 1. Build a report with Ship

Date going across the column area of the report.

2. Group the Ship Date field by month and year. 3. In the PivotTable Field List, drag the Years field to the Report Filter drop zone area of the pivot table. Use the dropdown in B1 to select one year from the data. 4. Drag the Order Date field to the row area of the pivot table. 5. Group the Order Date field by months and years. 6. Excel arbitrarily names the years field for Order Date as Years2, so rename the field Order

Year.

7. Double-click the Sum of Revenue label in cell A3. Choose the Show Values As tab. In the Show Values As drop-down, choose % of Column. 8. In the Data Field Settings dialog box, change the Custom Name box from Sum of Revenue to Percent of Sales. 9. While you are in the PivotTable Field Options dialog box, click the Number Format button. Give the Revenue field a custom number format of 0.0%;;.The semicolons suppress the display of negative and zero values. The resulting table is shown in Figure 4.8. Cell C11 indicates that 15.62% of the orders shipped in January 2009 were ordered during the month of January. Another 34.92% of those orders were received in December 2008.This means that 50.54% of the sales from January were received within the manufacturing lead time.This fact dictates that your manufacturing facility needs to keep a whole lot of inventory on hand to meet these short lead-time orders. Figure 4.8 The order lead-time report makes use of two fields grouped by month and year.

Grouping Numeric Fields The Grouping dialog box for numeric fields allows you to group items into equal ranges. In Figure 4.9, the Row Labels field contains a numeric age. Currently, the data shows ages from 20 through 75.

4

90

Chapter 4

Controlling the Way You View Your Pivot Data

Select any age in column A and choose Group Field from the Options dialog box. Excel displays the Grouping dialog box. In the Grouping dialog box, choose parameters for the group. In Figure 4.9, the dialog is suggesting groups from 20 to 75 in increments of 10 years.

Figure 4.9 Select an age and choose Group Field to display the Grouping dialog box.

The result, shown in Figure 4.10, summarizes the various ages in groups.

4 Figure 4.10 The numeric row field has been grouped into ranges.

C A S E S T U DY

Grouping Text Fields You get a call from the VP of Sales. Secretly, the Sales department is considering a massive reorganization of the sales regions.The VP would like to see a report showing sales for last year by the new proposed regions.You’ve been around long enough to know that the proposed regions will change several times before the reorganization happens, so you are not willing to change the Region field in your source data just yet. First, build a report showing revenue by market.The VP of Sales is proposing building a North region composed of Canada, Buffalo, Michigan, New York, and Seattle. Using the Ctrl key, highlight the five markets that make up the proposed North region. Figure 4.11 shows the pivot table before the first group is created.

Grouping Text Fields

91

Figure 4.11 Use the Ctrl key to select the noncontiguous cells that will make up the new North region.

From the Options ribbon, click Group Selection. Excel adds a new field called Market2.The five selected cells are sequenced together and belong to a Market2 grouping that is arbitrarily called Group1, as shown in Figure 4.12. Figure 4.12 Excel arbitrarily calls the first grouping Group1.

4

92

Chapter 4

Controlling the Way You View Your Pivot Data

Select Group1 in A4. Click the Field Settings icon on the Options ribbon. Give the field a name such as New

Region.

Click in cell A4 and type a meaningful name instead of Group1. As you repeat these steps to build other regions, Excel continues to assign names such as Group2, Group3, and so on. After creating each region, simply type a meaningful name over the cell containing the arbitrary group name. You will find that the New Region field is a real field.You can use the sorting feature (discussed later in this chapter) to sequence it alphabetically. By default, Excel does not add subtotals for the New Region field. Use the Subtotals drop-down on the Design ribbon to add subtotals. Figure 4.13 shows the report as it is ready for the VP of Sales.You can probably already predict that the Sales department will need to shuffle markets from the Central region to balance the regions. Figure 4.13 After you group all the markets into new regions, the report is ready for review.

4

Ungrouping After you have established groups, you can undo the groups by using the Ungroup icon on the Options ribbon. Simply select one of the grouped cells and then click the Ungroup icon.

Looking at the PivotTable Field List

93

Looking at the PivotTable Field List The next topics in this chapter involve sorting and filtering your pivot table. Both of these tasks involve subtleties in the PivotTable Field List. The following sections take you through a quick tour of the PivotTable Field List.

Docking and Undocking the PivotTable Field List The PivotTable Field List starts out docked on the right side of the Excel window. Grab the gray title bar for the pane and drag to the left to allow the pane to float anywhere in your Excel window. After you have undocked the PivotTable Field List, you might find that it is difficult to redock it on either side of the screen. To redock the Field List, you must grab the title bar and drag until at least 80% of the Field List is off the edge of the window. Pretend that you are trying to completely remove the floating Field List from the screen. Eventually, Excel will get the hint and redock the Field List. Note that the PivotTable Field List can be docked on either the right or left side of the screen.

Rearranging the PivotTable Field List As shown in Figure 4.14, a small drop-down appears near the top right of the PivotTable Field List. Select this drop-down to see the five possible arrangements of the PivotTable Field List. Although the default is to have the Fields section at the top of the list and the areas section at the bottom of the list, four other arrangements are possible.

Figure 4.14 Use this drop-down to rearrange the PivotTable Field List.

The final three arrangements offered in the drop-down are rather confusing. If someone changes the PivotTable Field List to show only the areas section, you could not see new fields to add to the pivot table. If you ever encounter a version of the PivotTable Field List with only the areas sections (see Figure 4.15) or only the fields, remember that you can return to a less confusing view of the data by using the arrangement drop-down.

4

94

Chapter 4

Controlling the Way You View Your Pivot Data

Figure 4.15 If you encounter this confusing arrangement of the PivotTable Field List, use the drop-down to return to an arrangement showing fields and areas.

Using the Areas Section Drop-Downs As shown in Figure 4.16, every field in the areas section has a visible drop-down arrow. When you select this drop-down arrow, you see four categories of choices:

4



The first four choices allow you to rearrange the field within the list of fields in that area of the pivot table.



The next four choices allow you to move the field to a new area. (However, this could easily be accomplished by dragging the field to a new area.)



The next choice allows you to remove the field from the pivot table.



The final choice displays the Field Settings dialog box for the field.

Because these drop-down arrows are always visible, you might be more likely to open these drop-downs. However, they are far less powerful than the hidden drop-downs in the Fields section of the list.

Using the Fields Drop-Down A second set of drop-downs is available in the PivotTable Field List. Hover the mouse cursor over any field in the Fields section of the PivotTable Field List, and a hidden drop-down arrow appears, as shown in Figure 4.17. After you open the drop-down in the Fields section, you can see that all the really useful sorting and filtering options are behind the hidden drop-down. Figure 4.18 shows the drop-down menu for the Product Line field in the top of the PivotTable Field List. Both the Label Filters and Value Filters options open to a flyout menu with many powerful filter choices.

Looking at the PivotTable Field List

95

Figure 4.16 The drop-downs in the areas section of the PivotTable Field List are not very useful.

4 Figure 4.17 You have to hover your mouse cursor over a field before you realize that a drop-down is available.

96

Chapter 4

Controlling the Way You View Your Pivot Data

CAUTION Microsoft has created a catch-22 for anyone trying to teach pivot tables. If this book suggests that you use the Product Line drop-down in the PivotTable Field List, most people would tend to use the drop-down visible in the areas section of the PivotTable Field List. For the rest of this chapter, when the text refers to the “Product drop-down in the Fields section of the PivotTable Field List,” you should use the hidden drop-down shown in Figure 4.18.

Figure 4.18 You shouldn’t be surprised that all the powerful features are in the drop-down that Microsoft hides from view.

4

Sorting in a Pivot Table By default, items in each pivot field are sorted in ascending sequence based on the item name. Microsoft has dramatically simplified pivot table sorting in Excel 2007. You have the freedom to sort your data fields to suit your needs. You can use one of several methods to apply sorting to your pivot table: ■

Using the Sorting buttons on the Options ribbon



Using the hidden drop-down in the Fields section of the PivotTable Field List



Using the manual method

Sorting Using the Sort Icons on the Options Ribbon Three icons appear in the Sort group of the Options ribbon. The AZ button sorts ascending. The ZA button sorts descending. The Sort icon brings up a dialog box with more options.

Sorting in a Pivot Table

97

To successfully use the Sort icons, you need to pay attention to where you place the cell pointer before clicking on the icon. In Figure 4.19, the pivot table is in the default sort order. The regions are sorted alphabetically (Midwest, North, South, West). Within each region, the markets are sorted alphabetically (Denver, Kansas City, Tulsa).

Figure 4.19 This pivot table is in the default sequence.

4

There are eight ways to sort this data. You get a different sort depending on whether you’ve selected A4, B4, A5, or B5 when you click the AZ or ZA buttons. Refer to Figure 4.19 when you read these options: ■

If you select cell A4 and click ZA, the regions are sorted in descending order. The West region appears first. Within the West region, the markets are still sorted in ascending sequence (California, Phoenix, Seattle).



If you select cell A5 and click ZA, the markets are sorted in descending order within each region. The markets in the West region appear in descending sequence (Seattle, Phoenix, California).



If you select cell B4 and click ZA, the regions are sorted so that the largest region appears first. This is the South region with $3.1 million, followed by the West region with $3 million. The markets retain their previous sequence.



If you select cell B5 and click ZA, the markets are sorted within each region so that the largest market appears first. In the South region, the Florida market appears first, with $1.5 million, followed by the Charlotte market with $891K.

98

Chapter 4

Controlling the Way You View Your Pivot Data

In Figure 4.20, the regions are sorted in descending alphabetical order, and the markets are sorted in descending revenue order within the regions.

Figure 4.20 After two sorts, the regions are in descending order alphabetically, and the markets are in descending order by region.

4 Think about sorting using the Data or Home ribbon; the sort is a one-time event. If data changes, you must manually choose to sort the data again. Pivot table sorts are more powerful. When you sort using the pivot table sorting options, Excel sets up a rule for the field. If you change the order of the pivot fields, Excel continues to apply the rule. In Figure 4.21, the Region field was removed from the report. Excel remembered that the Market field should be sorted by descending revenue. Excel properly re-sorted the data, moving Phoenix from row 6 to row 13.

Sorting Using the Field List Hidden Drop-Down An alternative method for sorting is to use the hidden drop-down in the Fields section of the PivotTable Field List. Hover the mouse cursor over any field in the top half of the PivotTable Field List, and a drop-down appears. Choose this drop-down to access AZ and ZA options, as well as a More Sort Options menu choice, as shown in Figure 4.22. You can use the More Sort Options choice to access the Sort dialog box, as shown in Figure 4.23. In this pivot table version of the Sort dialog box, you can choose to sort the specific field based on another field. In the figure, you can see that the customer field should be sorted into descending revenue sequence.

Sorting in a Pivot Table

99

Figure 4.21 Sort rules applied to a pivot table cause the data to be re-sorted after every pivot or refresh.

Figure 4.22 Use the drop-down in the Fields section of the PivotTable Field List to access sort options for a specific field.

4

100

Chapter 4

Controlling the Way You View Your Pivot Data

Figure 4.23 You can specify complex sort criteria by using this Sort dialog box.

Understanding the Effect of Layout Changes on AutoSort 4

If you change the report filter, the report automatically re-sorts. Different customers might appear at the top of the list based on their purchases of the filtered items. If you drop a new field on the report, the pivot table remembers the AutoSort option for the sorted field and does its best to present the data in that order. This may not be in the spirit of your report focusing on the best customers. Say that you add the Market field as the outer row field. The Market field is sorted alphabetically by name, but within each region, the customers are arranged in descending order by revenue.

Using a Manual Sort Sequence Note that the dialog box in Figure 4.23 offers something called a manual sort. Rather than using the dialog box, you can invoke a manual sort in a surprising way. Note that the regions in Figure 4.23 are in the order West, South, North, Midwest. If this company is based in New York, company traditions might dictate that the North region should be shown first, followed by South, West, and Midwest. On the face of it, there is no easy way to sort the Region field into this sequence. An ascending sort would cause the Midwest region to be first. A descending sort would cause the West region to be first. Neither sort will be in the proper sequence to match the company’s standard reporting. You might try to convince your company to change a decades-long tradition of reporting in the North, South, West, Midwest sequence, or even change the region names to accommodate sorting in your pivot table. Both of these concepts would be tough to sell and are not viable options. Luckily, Microsoft offers a simple solution to this problem. Place the cell pointer in cell B4 and type the word North. Excel figures out that you want to move the North column to be first and moves all the North values to column B. West is

Sorting in a Pivot Table

101

moved to column C, South moves to column D, and Midwest stays in column E. Next, type South in cell C4. The values in C and D switch places. This behavior is completely unintuitive. You should never try this behavior with a regular (nonpivot table) dataset in Excel. You would never expect Excel to change the column sequence just by moving the columns. Figure 4.24 shows the pivot table after typing new column headings in cells B4 and C4.

Figure 4.24 Simply type a heading in B4 to move a new region to be first.

CAUTION After you use this technique, any new regions you add to the data source are added at the end of the list. Figure 4.24 shows the pivot table after a region named Canada is added. Because Excel does not know where to add Canada, it automatically goes to the end of the list.

Using a Custom List for Sorting The other solution to the North, South, West, Midwest sequence problem is to set up a custom list. Custom lists are maintained in the Excel Options dialog box. Follow these steps to set up a custom list:

1. In an out-of-the-way section of the worksheet, type the regions in their proper sequence. Type one region per cell, going down a column.

2. Select the cells containing the list of regions in the proper sequence. 3. Select the Office Icon menu. Choose Excel Options from the bottom of the menu. 4. On the Popular category, click the Edit Custom Lists button. 5. In the Custom Lists dialog box, your selection address is entered in the Import text box. Click Import to bring the regions in as a new list, as shown in Figure 4.25. The new list appears at the bottom of the Custom Lists box.

6. Click OK to close the Custom Lists dialog box. Then click OK to close the Excel Options dialog box. The custom list is now stored on your computer and will be available for all future Excel sessions.

4

102

Chapter 4

Controlling the Way You View Your Pivot Data

Figure 4.25 Import a new custom list to enable custom sorts.

To sort the pivot table by the custom list, follow these steps:

1. Select one of the Region cells in the pivot table. 2. From the Options ribbon, click on the Sort icon. 3. In the Sort (Region) dialog box, choose Ascending by Region. 4. In the Sort (Region) dialog box, click the More Options button in the lower-left corner. 4

5. In the More Sort Options dialog box, uncheck the AutoSort checkbox. 6. As shown in Figure 4.26, in the More Sort Options dialog box, open the First Key Sort Order drop-down and choose North, South, West, Midwest.

7. Click OK twice.

Filtering the Pivot Table Pivot table veterans will remember the old page area section of a pivot table. This area has been renamed the report filter area and still operates basically the same as in previous versions. Microsoft did add the capability to select multiple items from the report filter area. However, Microsoft has added fantastic new filtering options that can be applied to fields in the column or row areas of a pivot table. It is a bit of a mystery why Microsoft did not rewrite the report filter area to have the same powerful options. As described in the following sections, you can choose items from fields in the report filter area. The new filtering options are accessed from the hidden drop-down in the Fields section of the PivotTable Field List.

CAUTION Although you can apply a filter to any field in the PivotTable Field List, the filter is active only if that field is in the row or column area of the pivot table!

Filtering the Pivot Table

103

Figure 4.26 Choose to sort by the custom list.

Adding Fields to the Report Filter Area The pivot table in Figure 4.27 is a perfect ad hoc reporting tool to give to a high-level executive. You can use the drop-downs in B1:B5 to quickly find revenue for any combination of region, market, state, customer, or invoice date. This is a typical use of report filters.

Figure 4.27 With multiple fields in the Report Filter drop zone, this pivot table can answer many ad hoc queries.

4

TIP

To set up the report, drag revenue to the Values drop zone and then drag as many fields as desired to the Report Filter drop zone.

If you add many fields to the report filter area, you might want to make use of one of the obscure pivot table options settings. Click Options on the Options ribbon. On the Layout & Format tab of the PivotTable Options dialog box, change the Report Filter Fields Per Column from 0 to a positive number. Excel rearranges the filter fields into multiple columns, as shown in Figure 4.28.You can also change Down,Then Over to Over,Then Down to rearrange the sequence of the filter fields.

104

Chapter 4

Controlling the Way You View Your Pivot Data

Figure 4.28 To show the filter fields in multiple columns, change this setting to be nonzero.

Report Filter Fields Per Column Filters arranged in multiple pairs of columns

4

Choosing One Item from a Report Filter To filter the pivot table, click on any drop-down in the report filter area of the pivot table. The drop-down always starts with (All), but then lists the complete unique set of items available in that field. To filter to a single item, click that item in the list, as shown in Figure 4.29.

Choosing Multiple Items from a Report Filter At the bottom of the report filter drop-down is a check box labeled Select Multiple Items. If you choose this box, Excel adds a check box next to each item in the drop-down. You can now check multiple items from the list. In Figure 4.30, the pivot table is filtered to show revenue from three markets.

CAUTION Using the Select Multiple Items filter leads to a situation in which the report consumer may not know what items are included in the report. In Figure 4.31, you can see that B2 reports the somewhat cryptic (Multiple Items) label.You should add a title to identify which markets are included in the report.

Filtering the Pivot Table

105

Figure 4.29 After you select this option, the report shows the revenue from the Kansas City market.

4

Figure 4.30 Use the Select Multiple Items check box to enable combination filters.

106

Chapter 4

Controlling the Way You View Your Pivot Data

Figure 4.31 This report includes multiple markets, but which ones?

Quickly Selecting or Clearing All Items from a Filter The (All) check box at the top of the Market drop-down in Figure 4.30 is powerful. Choosing the (All) check box represents a quick way to select or unselect all the items in the drop-down. If the (All) check box is unchecked, check it to select all items. If the (All) check box is checked, uncheck it to rapidly uncheck all items.

Using the Field List Filters Hover your mouse cursor over the Market field in the Fields section of the PivotTable Field List, and a drop-down appears. As shown in Figure 4.32, the bottom section of the drop-down is identical to the report filter drop-down after you’ve checked Select Multiple Items. You can use these check boxes as discussed previously to exclude certain items from the pivot table report. However, the drop-down shown in Figure 4.32 includes two additional powerful options: Label Filters and Value Filters. If Excel detects that your column contains dates, the Label Filters option is replaced with a Date Filters option. These options lead to a flyout menu with many powerful filtering options. These options are new in Excel 2007 and dramatically increase the efficiency of using pivot tables.

NOTE

4

You can access this drop-down either by hovering the mouse cursor over the item in the PivotTable Field List or by accessing the Column Labels or Row Labels drop-down in the pivot table. In Figure 4.33, there is only one field—Invoice Date—in the Row Labels drop zone, so using the Row Labels drop-down in cell A8 leads to a simple drop-down with the appropriate Date Filters and Value Filters entries.

Filtering the Pivot Table

107

Figure 4.32 The drop-down associated with the PivotTable Field List offers the same check box items as in the report filter fields.

4

Figure 4.33 If you have only one field in the row area, using the Row Labels dropdown is a suitable way to access the filter options.

108

Chapter 4

Controlling the Way You View Your Pivot Data

However, if you have two fields in the Row Labels drop zone of the report, the Row Labels drop-down is a bit more confusing. In Figure 4.34, both a date field and a text field occupy the row area of the pivot table. In this case, to use the Row Labels drop-down, you first have to use the Select Field drop-down at the top of the Row Labels drop-down. It is confusing to write this, but perhaps not as confusing to use it! You can use either the Field List drop-down or the Row Labels drop-down as you prefer.

Figure 4.34 When you have two Row Labels fields, you first have to use the Select Field drop-down within the first drop-down.

4

The next three sections discuss the various options available in the flyout menus in detail.

Using Label Filters The Label Filters flyout menu offers 14 different filter rules, as shown in Figure 4.35. When you choose one of the filter items from the menu, Excel displays the Label Filter dialog box. In this dialog box, you can use wildcard characters. Use an * to match any series of characters or use ? to match a single character. Figure 4.36 shows the Label Filter dialog box that appears after selecting Does Not End With. The options available in the Label Filters flyout menu include ■

Equals



Does Not Equal



Begins With

Filtering the Pivot Table



Does Not Begin With



Ends With



Does Not End With



Contains



Does Not Contain



Greater Than



Greater Than or Equal To



Less Than



Less Than or Equal To



Between



Not Between

109

Figure 4.35 Choose from the Label Filters rules in the flyout menu.

4

Using Date Filters If you select the drop-down for a field that contains predominantly dates, the Date Filters flyout menu offers many canned date periods, as shown in Figure 4.37. If you select Equals, Before, After, or Between, you can specify a date or a range of dates.

110

Chapter 4

Controlling the Way You View Your Pivot Data

Figure 4.36 After you choose a label filter, you complete the filter in this dialog box.

Figure 4.37 Microsoft offers a fantastic but not all-inclusive list of date filters.

4

Options for the current, past, or next day; week; month; quarter; or year occupy 15 options. Combined with Year to Date, these options change day after day. You could pivot a list of projects by due date and always see the projects that are due in the next week using this option. When you open the workbook on another day, the report will recalculate.

TIP

Filtering the Pivot Table

111

In Microsoft’s world, a week runs from Sunday through Saturday. If you select Next Week, the report always shows a period from the next Sunday through the following Saturday.

NOTE

When you choose All Dates in the Period, a new flyout menu offers options such as Each Month and Each Quarter.

People who use QuickBooks will recognize that this list is reminiscent of the reporting options that have been available in QuickBooks for several versions. Unfortunately, Microsoft left out a few key choices such as This Month to Date, Last Week to Date, and Next 4 weeks.

If you are frustrated that there is not a Last Week to Date option, you might have some hope that the Custom choice in the filter will solve the problem. Unfortunately, this hope is unfounded because the Custom date filter leads to a dialog box offering only a subset of the choices already on the menu.

Using Value Filters The value filter is a powerful feature. It allows you to filter one of your row or column fields based on the numbers that appear in the values area of the pivot table. Figure 4.38 shows a pivot table with revenue and hours by market.

Figure 4.38 The row field contains market names.

Can you filter the markets based on the revenue values in column B? To do so, select the Row Labels drop-down. Then choose Value Filters to see the flyout menu shown in Figure 4.39.

4

112

Chapter 4

Controlling the Way You View Your Pivot Data

Figure 4.39 Even though you are filtering the Market field, these menu choices do not refer to values in the Market column.

When you access the Value Filter dialog box, you can specify that the Market field should be filtered based on the numeric values in a particular value field. In Figure 4.40, you are specifying that the report should show only markets with more than 10,000 billable hours.

4 Figure 4.40 In this dialog box, you choose a numeric field name and then specify the filter.

The resulting pivot table, shown in Figure 4.41, shows all the markets with more than 10,000 billable hours.

Creating a Top 10 Report

113

Figure 4.41 The report is limited to states that match the 10,000-hour threshold.

C A S E S T U DY

Creating a Top 10 Report One of the cool value filters is the Top 10 filter.This choice can be used to select the Top N, Bottom N,Top N%, or Bottom N%. For a value filter, you can select text row fields where the corresponding value fields are in the top 10, top 20, and so on. In Figure 4.42, the pivot table shows revenue by customer. Because there are more than 6,000 customers, your hope of getting any sales manager to read this report is slim. It would be much better to show a report of the top 20 customers. Figure 4.42 There are too many customers to read the whole report.

4

114

Chapter 4

Controlling the Way You View Your Pivot Data

Follow these steps to filter the report: 1. Select the Row Labels drop-down in cell A2. 2. Choose Value Filters from the drop-down. 3. Choose Top 10 from the flyout menu. Excel displays the Top 10 Filter (Customer) dialog box, as shown in Figure 4.43. Figure 4.43 Initially, the Top 10 Filter offers to find the top 10 customers.

4. Change the settings in the dialog box to specify that the report should filter to the top 20 items based on Sum of Revenue, as shown in Figure 4.44. Figure 4.44 4

Change the dialog box to choose the top 20 customers.

5. Click OK to close the dialog box.Your pivot table then shows only the top 20 customers. 6. If you wish the customers to be listed high to low, choose More Sort Options from the Row Labels drop-down. Excel displays the Sort dialog box. 7. Specify that the customers should be sorted in descending order based on the Sum of Revenue field, as shown in Figure 4.45. As shown in Figure 4.46, the result is a compact pivot table showing the largest customers in descending order by revenue.

Creating a Top 10 Report

115

Figure 4.45 Specify that the customers should be sorted high to low.

Figure 4.46 A top 20 customer report is easy to create using the Top 10 filter.

4

116

Chapter 4

Controlling the Way You View Your Pivot Data

Next Steps In the next chapter, you learn how to use pivot table formulas to add entire new virtual fields to your pivot table.

4

Performing Calculations Within Your Pivot Tables Introducing Calculated Fields and Calculated Items When analyzing data with pivot tables, you will often find the need to expand your analysis to include data based on calculations that are not in your original dataset. Excel provides a way to perform calculations within your pivot table through calculated fields and calculated items. A calculated field is a data field you create by executing a calculation against existing fields in the pivot table. Think of a calculated field as adding a virtual column to your dataset. This column takes up no space in your source data, contains the data you define with a formula, and interacts with your pivot data as a field—just like all the other fields in your pivot table. A calculated item is a data item you create by executing a calculation against existing items within a data field. Think of a calculated item as adding a virtual row of data to your dataset. This virtual row takes up no space in your source data and contains summarized values based on calculations performed on other rows in the same field. Calculated items interact with your pivot data as a data item—just like all the other items in your pivot table. With calculated fields and calculated items, you can insert a formula into your pivot table to create your own custom field or data item. Your newly created data becomes a part of your pivot table, interacting with other pivot data, recalculating when you refresh and supplying you with a calculated metric that does not exist in your source data. The example in Figure 5.1 demonstrates how a basic calculated field can add another perspective on your data. Your pivot table shows total sales

5 IN THIS CHAPTER Introducing Calculated Fields and Calculated Items . . . . . . . . . . . . . . . . . . . . . . .117 Creating Your First Calculated Field . . . . . . . .121 Case Study: Summarizing Next Year’s Forecast . . . . . . . . . . . . . . . . . . . . . . . . .124 Creating Your First Calculated Item . . . . . . . .129 Understanding Rules and Shortcomings of Pivot Table Calculations . . . . . . . . . . . . . . .133 Managing and Maintaining Your Pivot Table Calculations . . . . . . . . . . . . . . . . .137 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140

118

Chapter 5

Performing Calculations Within Your Pivot Tables

amount and contracted hours for each market. A calculated field that shows you average dollar per hour enhances this analysis and adds another dimension to your data.

Figure 5.1 Avg Dollar per Hour is a calculated field that adds another perspective to your data analysis.

Now, you may look at Figure 5.1 and ask yourself: Why go through all the trouble of creating calculated fields or calculated items? Why not just use formulas in surrounding cells or even add your calculation directly into the source table to get the information you need? To answer these questions, look at the different methods you could use to create the calculated field in Figure 5.1.

5

Method 1: Manually Add the Calculated Field to Your Data Source You can manually add a calculated field to your data source, as shown in Figure 5.2, allowing the pivot table to pick up the field as a regular data field. On the surface, this option looks simple, but this method of precalculating metrics and incorporating them into your data source is impractical on several levels. If the definitions of your calculated fields change, you will have to go back to the data source, recalculate the metric for each row, and refresh your pivot table. If you have to add a metric, you will have go back to the data source, add a new calculated field, and then change the range of your pivot table to capture the new field.

Method 2: Use a Formula Outside Your Pivot Table to Create the Calculated Field You can add a calculated field by performing the calculation in an external cell with a formula. In the example shown in Figure 5.3, the Average Dollar Per Hour column was created with formulas referencing the pivot table.

Introducing Calculated Fields and Calculated Items

119

Figure 5.2 Precalculating calculated fields in your data source is both cumbersome and impractical.

Figure 5.3 Typing a formula next to your pivot table essentially gives you a calculated field that refreshes when your pivot table is refreshed.

5 Although this method gives you a calculated field that updates when your pivot table is refreshed, any changes in the structure of your pivot table have the potential of rendering your formula useless. As you can see in Figure 5.4, moving the Market field to the report filter area changes the structure of your pivot table, exposing the weakness of makeshift calculated fields that use external formulas.

Method 3: Insert a Calculated Field Directly into Your Pivot Table Inserting the calculated field directly into your pivot table is the best option, eliminating the need to manage formulas, providing for scalability when your data source grows or changes, and allowing for flexibility in the event that your metric definitions change. Another huge advantage of this method is that you can alter your pivot table’s structure and even measure different data fields against your calculated field without worrying about errors in your formulas or losing cell references.

120

Chapter 5

Performing Calculations Within Your Pivot Tables

Figure 5.4 External formulas run the risk of errors when the pivot table structure is changed.

The pivot table report shown in Figure 5.5 is the same one you see in Figure 5.1, except it has been restructured so that you get the average dollar per hour by market and product.

Figure 5.5 Your calculated field remains viable even when your pivot table’s structure changes to accommodate new dimensions.

5

The bottom line is that there are significant benefits in integrating your custom calculations into your pivot table, including ■

The elimination of potential formula and cell reference errors



The ability to add and remove data from your pivot table without affecting your calculations



The ability to auto-recalculate when your pivot table is changed or refreshed



The flexibility to change calculations easily when your metric definitions change



The ability to manage and maintain your calculations effectively

Creating Your First Calculated Field

121

Creating Your First Calculated Field Before you create a calculated field, you must first have a pivot table. Build the pivot table you see here in Figure 5.6.

Figure 5.6 Create the pivot table shown here.

Now that you have a pivot table, it’s time to create your first calculated field. To do this, you must activate the Insert Calculated Field dialog box. Select Options under the PivotTable Tools tab and then select Formulas from the Tools group. Selecting this option activates a drop-down menu from which you can select Calculated Field, as demonstrated in Figure 5.7.

Figure 5.7 Start the creation of your calculated field by selecting Formulas and then Calculated Field.

5

122

Chapter 5

Performing Calculations Within Your Pivot Tables

After you select Calculated Field, Excel activates the Insert Calculated Field dialog box, as shown in Figure 5.8.

Figure 5.8 The Insert Calculated Field dialog box assists you in creating a calculated field in your pivot table.

Notice the two input boxes, Name and Formula, at the top of the dialog box. The objective here is to give your calculated field a name and then build the formula by selecting the combination of data fields and mathematical operators that provide the metric you are looking for.

5

As you can see in Figure 5.9, you first give your calculated field a descriptive name—that is, a name that describes the utility of the mathematical operation. In this case, enter Average Dollar per Hour in the Name input box.

Figure 5.9 Give your calculated field a descriptive name.

Creating Your First Calculated Field

123

Next, you go to the Fields list and double-click on the Sales_Amount field. Then enter / to let Excel know you plan to divide the Sales_Amount field by something.

CAUTION By default, the Formula input box in the Insert Calculated Field dialog box contains = 0. Ensure that you delete the 0 before continuing with your formula.

At this point, your dialog box should look similar to the one shown in Figure 5.10.

Figure 5.10 Start your formula with = Sales_Amount /.

Next, double-click on the Contracted Hours field to finish your formula, as illustrated in Figure 5.11.

Figure 5.11 The full formula, = Sales_Amount/ ‘Contracted Hours’, gives you the

calculated field you need.

5

124

Chapter 5

Performing Calculations Within Your Pivot Tables

Finally, select Add and then click OK to create your newly created calculated field. As you can see in Figure 5.12, not only does your pivot table create a new field called Sum of Average Dollar Per Hour, but the PivotTable Field List includes your new calculated field as well.

Figure 5.12

NOTE

You can change the settings on your new calculated field just as you would any other field (that is, change the field name, change the number format, change the color).

5

The resulting values from a calculated field are not formatted.You can easily apply any desired formatting using some of the techniques you learned in Chapter 3,“Customizing a Pivot Table.”

Does this mean you have just added a column to your data source? The answer is no. Calculated fields are similar to the pivot table’s default subtotal and grand total calculations in that they are all mathematical functions that recalculate when the pivot table changes or is refreshed. Calculated fields merely mimic the hard fields in your data source, allowing you to drag them, change field settings, and use them with other calculated fields. Take a moment and look at Figure 5.11 closely. Notice the formula you entered is in a format similar to the one used in the standard Excel formula bar. The obvious difference is that instead of using hard numbers or cell references, you are referencing pivot data fields to define the arguments used in this calculation. If you have worked with formulas in Excel before, you will quickly grasp the concept of creating calculated fields.

C A S E S T U DY

Summarizing Next Year’s Forecast All the branch managers in your company have submitted their initial revenue forecasts for next year.Your task is to take the first-pass numbers they submitted and create a summary report showing the following: Total revenue forecast by market Total percent growth over last year Total contribution margin by market

Summarizing Next Year’s Forecast

125

Because these numbers are first-pass submissions and you know they will change over the course of the next two weeks, you decide to use a pivot table to create the requested forecast summary. Start by building the initial pivot table, shown here in Figure 5.13, to include Revenue Last Year and Forecast Next Year for each market. After creating the pivot table, you will see that by virtue of adding the Forecast Next Year field in the data area, you have met your first requirement: to show total revenue forecast by market. Figure 5.13 The initial pivot table is basic, but it provides the data for your first requirement: show total revenue forecast by market.

5 The next metric you need is percent growth over last year.To get this data, you need to add a calculated field that calculates the following formula: (Forecast Next Year / Revenue Last Year) – 1 To achieve this, do the following: 1. Activate the Insert Calculated Field dialog box and name your new field Percent 2. Delete the 0 in the Formula input box. 3. Enter ( (an open parenthesis). 4. Double-click on the Forecast Next Year field. 5. Enter / (a division sign). 6. Double-click on the Revenue Last Year field. 7. Enter ) (a close parenthesis). 8. Enter - (a minus sign). 9. Enter the number 1.

Growth (see Figure 5.14).

126

Chapter 5

Performing Calculations Within Your Pivot Tables

Figure 5.14 Name your new field

TIP

Percent Growth.

You can use any constant in your pivot table calculations. Constants are static values that do not change. In this example, the number 1 is a constant.Though the value of Revenue Last Year or Forecast Next Year may change based on the available data, the number 1 will always have the same value.

After you have entered the full formula, your dialog box should look similar to the one shown in Figure 5.15. 5

Figure 5.15 With just a few clicks, you have created a variance formula!

Summarizing Next Year’s Forecast

127

With your formula typed in, you can now click OK to add your new field. After changing the format of the resulting values to percent, you have a nicely formatted Percent Growth calculation in your pivot table. At this point, your pivot table should look like the one shown in Figure 5.16. Figure 5.16 You have added a Percent Growth calculation to your pivot table.

With this newly created view into your data, you can easily see that three markets need to resubmit their forecasts to reflect positive growth over last year. Figure 5.17 You can already discern some information from the calculated field, identifying three problem markets.

Now it’s time to focus on your last requirement, which is to find total contribution margin by market.To get this data, you need to add a calculated field that calculates the following formula: Forecast Next Year + Variable Cost Next Year

5

Chapter 5

Performing Calculations Within Your Pivot Tables

NOTE

128

A quick look at Figure 5.17 confirms that the Variable Cost Next Year field is not displayed in the pivot table report. Can you build pivot table formulas with fields that are not currently even in the pivot table? The answer is yes; you can use any field that is available to you in the PivotTable Field List, regardless of the fact that the field is not shown in the pivot table itself.

To create this field, do the following: 1. Activate the Insert Calculated Field dialog box and name your new field Contribution

Margin.

2. Delete the 0 in the Formula input box. 3. Double-click on the Forecast Next Year field. 4. Enter + (a plus sign). 5. Double-click on the Variable Cost Next Year field. After you have entered the full formula, your dialog box should look similar to the one shown in Figure 5.18. Figure 5.18 With just a few clicks, you have created a formula that calculates contribution margin.

5

With the creation of the contribution margin, this report is ready to be delivered (see Figure 5.19).

Creating Your First Calculated Item

129

Figure 5.19 Contribution margin is now a data field in your pivot table report thanks to your calculated field.

Now that you’ve built your pivot table report, you can easily analyze any new forecast submissions by refreshing your report with the new updates.

Creating Your First Calculated Item As you learned at the beginning of this chapter, a calculated item is a virtual data item you create by executing a calculation against existing items within a data field. Calculated items come in especially handy when you need to group and aggregate a set of data items. For example, the pivot table in Figure 5.20 gives you sales amount by Sales_Period. Imagine that you need to compare the average performance of the most recent six Sales_Periods to the average of the prior seven periods. That is, you want to take the average of P01–P07 and compare it to the average of P08–P13. Place your cursor on any data item in the Sales_Period field and then select Formulas from the Tools group. Next, select Calculated Item, as shown in Figure 5.21. Selecting this option opens the Insert Calculated Item dialog box. A quick glance at Figure 5.22 shows you that the top of the dialog box identifies which field you are working with. In this case, it is the Sales_Period field. In addition, notice the Items list box is automatically filled with all the items in the Sales_Period field. Your goal is to give your calculated item a name and then build its formula by selecting the combination of data items and operators that provide the metric you are looking for.

5

130

Chapter 5

Performing Calculations Within Your Pivot Tables

Figure 5.20 You want to compare the most recent six Sales_Periods to the average of the prior seven periods.

Figure 5.21 Start the creation of your calculated item by selecting Formulas and then Calculated Item.

5

In this example, name your first calculated item Avg

P1-P7 Sales,

as shown in Figure 5.23.

Next, you can build your formula in the Formula input box by selecting the appropriate data items from the Items list. In this scenario, you want to create the following formula: Average(P01, P02, P03, P04, P05, P06, P07)

Creating Your First Calculated Item

131

Figure 5.22 The Insert Calculated Item dialog box is automatically populated to reflect the field with which you are working.

Figure 5.23 Give your calculated item a descriptive name.

5

Enter this formula into the Formula input box, as demonstrated in Figure 5.24. Click OK to activate your new calculated item. As you can see in Figure 5.25, you now have a data item called Avg P1-P7 Sales.

132

Chapter 5

Performing Calculations Within Your Pivot Tables

Figure 5.24 Enter a formula that gives you the average of P01–P07.

Figure 5.25 You have successfully added a calculated item to your pivot table.

TIP

5

You can use any worksheet function in both a calculated field and a calculated item.The only restriction is that the function you use cannot reference external cells or named ranges. In effect, this means you can use any worksheet function that does not require cell references or defined names to work (such as COUNT, AVERAGE, IF, OR).

Understanding Rules and Shortcomings of Pivot Table Calculations

133

Create a calculated item to represent the average sales for P08–P13, as demonstrated in Figure 5.26.

Figure 5.26 Create a second calculated item.

Now you can hide the individual sales periods, leaving only your two calculated items. After a little formatting, your calculated items, shown in Figure 5.27, allow you to compare the average performance of the six most recent Sales_Periods to the average of the prior seven periods.

Figure 5.27 You can now compare the most recent six Sales_Periods to the average of the prior seven periods.

5

CAUTION If you don’t hide the data items you used to create your calculated item, your grand totals and subtotals may show incorrect amounts.

Understanding Rules and Shortcomings of Pivot Table Calculations Although there is no better way to integrate your calculations into a pivot table than using calculated fields and calculated items, they do come with their own set of drawbacks. It’s

134

Chapter 5

Performing Calculations Within Your Pivot Tables

important you understand what goes on behind the scenes when you use pivot table calculations, and even more important to be aware of the boundaries and limitations of calculated fields and calculated items to avoid potential errors in your data analysis. The following sections highlight the rules around calculated fields and calculated items that you will most likely encounter when working with pivot table calculations.

Remembering the Order of Operator Precedence Just as in a spreadsheet, you can use any operator in your calculation formulas, meaning any symbol that represents a calculation to perform (+, –, *, /, %, ^). Moreover, just as in a spreadsheet, calculations in a pivot table follow the order of operator precedence. In other words, when you perform a calculation that combines several operators, as in (2+3) * 4/50%, Excel evaluates and performs the calculation in a specific order. The order of operations for Excel is as follows: Evaluate items in parentheses.



Evaluate ranges (:).



Evaluate intersections (spaces).



Evaluate unions (,).



Perform negation (–).



Convert percentages (%).



Perform exponentiation (^).



Perform multiplication (*) and division (/), which are of equal precedence.



Perform addition (+) and subtraction (-), which are of equal precedence.



Evaluate text operators (&).



Perform comparisons (=, , =).

NOTE

5



Operations that are equal in precedence are performed left to right.

Consider this basic example. The correct answer to (2+3)*4 is 20. However, if you leave off the parentheses, as in 2+3*4, Excel performs the calculation like this: 3*4 = 12 + 2 = 14. The order of operator precedence mandates that Excel perform multiplication before subtraction. Entering 2+3*4 gives you the wrong answer. Because Excel evaluates and performs all calculations in parentheses first, placing 2+3 inside parentheses ensures the correct answer. Here is another widely demonstrated example. If you enter 10^2, which represents the exponent 10 to the 2nd power as a formula, Excel returns 100 as the answer. If you enter –10^2, you would expect –100 to be the result. Instead, Excel returns 100 yet again. The reason is that Excel performs negation before exponentiation, meaning Excel is converting

Understanding Rules and Shortcomings of Pivot Table Calculations

135

10 to –10 before the exponentiation, effectively calculating –10*–10, which indeed equals 100. Using parentheses in the formula, –(10^2), ensures that Excel calculates the exponent before negating the answer, giving you –100. Understanding the order of operations ensures that you avoid miscalculating your data.

Using Cell References and Named Ranges When you create calculations in a pivot table, you are essentially working in a vacuum. The only data available to you is the data that exists in the pivot cache. Therefore, you cannot reach outside the confines of the pivot cache to reference cells or named ranges in your formula.

Using Worksheet Functions You can use any worksheet function that does not require cell references or defined names as an argument. In effect, this means you can use any worksheet function that does not require cell references or defined names to work. Of the many functions that fall into this category, some include COUNT, AVERAGE, IF, AND, NOT, OR.

Using Constants You can use any constant in your pivot table calculations. Constants are static values that do not change. For example, in the formula [Units Sold]*5, 5 is a constant. Though the value of Units Sold may change based on the available data, 5 will always have the same value.

Referencing Totals Your calculation formulas cannot reference a pivot table’s subtotals or grand total. This means that you cannot use the result of a subtotal or grand total as a variable or argument in your calculated field.

Rules Specific to Calculated Fields Calculated field calculations are always performed against the sum of your data. In basic terms, Excel always calculates data fields, subtotals, and grand totals before evaluating your calculated field. This means that your calculated field is always applied to the sum of the underlying data. The example shown in Figure 5.28 demonstrates how this can adversely affect your data analysis. In each quarter, you need to get the total revenue for every product by multiplying the number of units sold by the price. If you look at Q1 first, you can immediately see the problem. Instead of returning the sum of 220+150+220+594, which would give you $1,184, the subtotal is calculating the sum of number of units times the sum of price, which returns the wrong answer.

5

136

Chapter 5

Performing Calculations Within Your Pivot Tables

Figure 5.28 Although the calculated field is correct for the individual data items in your pivot table, the subtotal is mathematically incorrect.

As you can see in Figure 5.29, including the whole year in your analysis compounds the problem.

Figure 5.29 The grand total for the year as a whole is completely wrong.

5 Unfortunately, there is no solution to this problem, but there is a workaround. In worstcase scenarios, you can configure your settings to eliminate subtotals and grand totals and then calculate your own Totals. Figure 5.30 demonstrates this workaround.

Rules Specific to Calculated Items You cannot use calculated items in a pivot table that uses averages, standard deviations, or variances. Conversely, you cannot use averages, standard deviations, or variances in a pivot table that contains a calculated item. You cannot use a page field to create a calculated item, nor can you move any calculated item to the report filter area. You cannot add a calculated item to a report that has a grouped field, nor can you group any field in a pivot table that contains a calculated item. When building your calculated item formula, you cannot reference items from a field other than the one you are working with.

Managing and Maintaining Your Pivot Table Calculations

137

Figure 5.30 Calculating your own Totals can prevent reporting incorrect data.

As you think about the section you have just read, don’t be put off by these shortcomings of pivot tables. Despite the clear limitations highlighted, the capability to create custom calculations directly into your pivot table remains a powerful and practical feature that can enhance your data analysis. Now that you are aware of the inner workings of pivot table calculations and understand the limitations of calculated fields and items, you can avoid the pitfalls and use this feature with confidence.

Managing and Maintaining Your Pivot Table Calculations In your dealings with pivot tables, you will find that sometimes you won’t keep a pivot table for more than the time it takes to say, “Copy, Paste Values.” Other times, however, it will be more cost effective to keep your pivot table and all its functionality intact. When you find yourself maintaining and managing your pivot tables through changing requirements and growing data, you may find the need to maintain and manage your calculated fields and calculated items as well.

Editing and Deleting Your Pivot Table Calculations When your calculation’s parameters change or you no longer need your calculated field or calculated item, you can activate the appropriate dialog box to edit or remove the calculation. Simply activate the Insert Calculated Field or Insert Calculated Item dialog box and select the Name drop-down, as demonstrated in Figure 5.31. As you can see in Figure 5.32, after you select a calculated field or item, you have the option of deleting the calculation or modifying the formula.

5

138

Chapter 5

Performing Calculations Within Your Pivot Tables

Figure 5.31 Opening the drop-down list under Name reveals all the calculated fields or items in the pivot table.

Figure 5.32 After you select the appropriate calculated field or item, you can either delete or modify the calculation.

5

Changing the Solve Order of Your Calculated Items If the value of a cell in your pivot table is dependent on the results of two or more calculated items, you have the option of changing the solve order of the calculated items. That is, you can specify the order in which the individual calculations are performed. To get to the Solve Order dialog box, place your cursor anywhere in the pivot table, select Formulas from the Tools group, and then select Solve Order, as shown in Figure 5.33.

Managing and Maintaining Your Pivot Table Calculations

139

Figure 5.33 Activate the Solve Order dialog box by selecting Formulas and then Solve Order.

The Solve Order dialog box, shown here in Figure 5.34, lists all the calculated items that currently exist in your pivot table. The idea here is to select any of the calculated items you see listed to enable the Move Up, Move Down, and Delete command buttons. The order you see the formulas in this list is the exact order the pivot table will perform each operation.

Figure 5.34 After you identify the calculated item you are working with, simply move the item up or down to change the solve order.You also have the option of deleting the item in this dialog box.

Documenting Your Formulas Excel provides a nice little function that lists the calculated fields and calculated items used in your pivot table, along with details on the solve order and formulas. This feature comes in especially handy if you need to quickly determine what calculations are being applied in a pivot table and which fields or items those calculations affect. To list your pivot table calculations, simply place your cursor anywhere in the pivot table and select Formulas and then select List Formulas. Excel creates a new tab in your workbook listing the calculated fields and calculated items in the current pivot table. Figure 5.35 shows a sample output of the List Formulas command.

5

140

Chapter 5

Performing Calculations Within Your Pivot Tables

Figure 5.35 The List Formulas command allows you to document the details of your pivot table calculations quickly and easily.

Next Steps In the next chapter, you learn the fundamentals of pivot charts and the basics of representing your pivot data graphically. You also get a firm understanding of the limitations of pivot charts and alternatives to using pivot charts.

5

Using Pivot Charts and Other Visualizations What Is a Pivot Chart…Really? When sharing your analyses with others, you will quickly find that there is no getting around the fact that people want charts. Pivot tables are nice, but they leave lots of those pesky numbers that take time to absorb. Charts, on the other hand, enable users to make a split-second determination on what your data is actually revealing. Charts offer instant gratification, allowing users to immediately see relationships, point out differences, and observe trends. The bottom line is that managers today want to absorb data as fast as possible, and nothing delivers that capability faster than a chart. This is where pivot charts come into play. Whereas pivot tables offer the analytical, pivot charts offer the visual. A common definition of a pivot chart is a graphical representation of the data in your pivot table. Although this definition is technically correct, it somehow misses the mark on what a pivot chart truly does. When you create a standard chart from data that is not in a pivot table, you feed the chart a range made up of individual cells holding individual pieces of data. Each cell is an individual object with its own piece of data, so your chart treats each cell as an individual data point, charting each one separately. However, the data in your pivot table is part of a larger object. The pieces of data you see inside your pivot table are not individual pieces of data that occupy individual cells. Rather, they are items inside a larger pivot table object that is occupying space on your worksheet. When you create a chart from your pivot table, you are not feeding it individual pieces of data inside individual cells; you are feeding it the entire pivot

6 IN THIS CHAPTER What Is a Pivot Chart…Really? . . . . . . . . . . .141 Creating Your First Pivot Chart . . . . . . . . . . . .142 Keeping Pivot Chart Rules in Mind . . . . . . . .145 Case Study: Creating a Report Showing Invoice Frequency and Revenue Distribution by Product . . . . . . . . . . . . . . . . .148 Examining Alternatives to Using Pivot Charts . . . . . . . . . . . . . . . . . . . . . . . . . . .153 Using Conditional Formatting with Pivot Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . .157 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . .166

142

Chapter 6

Using Pivot Charts and Other Visualizations

table layout. Indeed, a true definition of a pivot chart is a chart that uses a PivotLayout Object to view and control the data in your pivot table. Using the PivotLayout Object allows your pivot chart to interactively add, remove, filter, and refresh data fields inside the chart just like your pivot table. The result of all this action is a graphical representation of the data you see in your pivot table.

Creating Your First Pivot Chart With all the complexity behind the make-up of a pivot chart, you may get the impression that creating them is difficult. The reality is that it’s quite a simple task. To demonstrate how simple it is to create a pivot chart, look at the pivot table in Figure 6.1. This pivot table provides for a simple view of revenue by market. The Business Segment field in the report filter area lets you parse out revenue by line of business.

Figure 6.1 This basic pivot table shows revenue by market and allows for filtering by line of business.

6

Creating a pivot chart from this data would not only allow for an instant view of the performance of each market, but would also permit you to retain the ability to filter by line of business. To start the process, place your cursor anywhere inside the pivot table and click the Insert tab on the Application ribbon. On the Insert tab, you can see the Charts group displaying the various types of charts you can create. Here, you can choose the chart type you would like to use for your pivot chart. For this example, click on the Column chart icon and select the first 2-D column chart, as demonstrated in Figure 6.2.

Creating Your First Pivot Chart

143

Figure 6.2 Select the chart type you want to use.

As you can see in Figure 6.3, choosing the chart type causes two objects to appear on your spreadsheet: a column chart and the PivotChart Filter Pane.

Figure 6.3

TIP

Excel creates your pivot chart on the same sheet as your pivot table.

Notice that pivot charts are now, by default, placed on the same sheet as the source pivot table. If you long for the days when pivot charts were located on their own chart sheet, you are in luck. All you have to do is place your cursor inside your pivot table and then press F11 on your keyboard.This creates a pivot chart on its own sheet. By the way, you can easily change the location of your pivot charts by simply right-clicking on the chart itself (outside the plot area) and selecting Move Chart.This activates the Move Chart dialog box, where you can specify the new location.

6

144

Chapter 6

Using Pivot Charts and Other Visualizations

A Few Words on the PivotChart Filter Pane In previous versions of Excel, pivot charts displayed the available pivot fields directly on the charts. Using these pivot fields, a user could rearrange a chart and apply filters to the underlying pivot table, thus filtering the chart. In Excel 2007, the pivot fields have been removed from pivot charts.This ensures that pivot charts in Excel 2007 have a clean look and feel consistent with standard charts. In place of the pivot fields, Excel provides the PivotChart Filter Pane.This task pane allows you to limit the data shown in the pivot chart by applying filters to the underlying pivot table.You can filter your pivot table here using the same techniques highlighted in Chapter 4,“Controlling the Way You View Your Pivot Data.”You are also able to call the PivotTable Field List dialog box from here, where you can rearrange the fields in your pivot table. The PivotChart Filter Pane appears each time you place your cursor inside the pivot chart and disappears when you click outside the pivot chart.You can prevent this task pane from automatically activating by explicitly closing it. After you disable this task pane, you can reactivate it by choosing PivotChart Filter from the Analyze tab on the PivotChart Tools ribbon. Click anywhere inside the pivot chart to activate the PivotChart Tools ribbon. You now have a chart that is a visual representation of your pivot table. More than that, because the pivot chart is tied to the underlying pivot table, changing the pivot table in any way changes the chart. For example, as Figure 6.4 illustrates, adding the Region field to the pivot table adds a region dimension to your chart.

Figure 6.4 Your pivot chart displays the same fields your underlying pivot table displays.

NOTE

6 The pivot chart in Figure 6.4 does not display the subtotals shown in the pivot table.When creating a pivot chart, Excel ignores subtotals and grand totals.

In addition, selecting a Business Segment from the page field filters not only the pivot table, but also the pivot chart. All this behavior comes from the fact that pivot charts use the same pivot cache and pivot layout as their corresponding pivot tables. This means that if you add or remove data from your data source and refresh your pivot table, your pivot chart updates to reflect the changes.

Keeping Pivot Chart Rules in Mind

145

Take a moment and think about the possibilities. You can essentially create a fairly robust interactive reporting tool on the power of one pivot table and one pivot chart; no programming necessary.

Creating a Pivot Chart from Scratch You don’t have to build your pivot table before creating a pivot chart.You can go straight from your raw data to a pivot chart. Simply click on any single cell in your data source and select the Insert tab. From there, select PivotTable from the Tables group and choose PivotChart from the drop-down list.This activates the Create PivotChart dialog box. At this point, you go through the same steps you would take if you were building a pivot table.

Keeping Pivot Chart Rules in Mind As with other aspects of pivot table technology, pivot charts come with their own set of rules and limitations. The following sections give you a better understanding of the boundaries and restrictions of pivot charts.

Changes in the Underlying Pivot Table Affect Your Pivot Chart The primary rule you should always be cognizant of is that your pivot chart is merely an extension of your pivot table. If you refresh, move a field, add a field, remove a field, hide a data item, show a data item or apply a filter, your pivot chart reflects your changes.

The Placement of Data Fields in Your Pivot Table May Not Be Best Suited for Your Pivot Chart One common mistake people make when using pivot charts is assuming that Excel will place the values in the column area of the pivot table in the x-axis of the pivot chart. For instance, the pivot table in Figure 6.5 is in a format that is easy to read and comprehend. The structure chosen shows Sales Periods in the column area and the Region in the row area. This structure works fine in the pivot table view.

Figure 6.5 The placement of your data fields works for a pivot table view.

Suppose you decide to create a pivot chart from this pivot table. You would instinctively expect to see fiscal periods across the x-axis and lines of business along the y-axis. However,

6

146

Chapter 6

Using Pivot Charts and Other Visualizations

as you can see in Figure 6.6, your pivot chart comes out with Region in the x-axis and Sales Period in the y-axis.

Figure 6.6 Creating a pivot chart from your nicely structured pivot table does not yield the results you were expecting.

So why does the structure in your pivot table not translate to a clean pivot chart? The answer has to do with the way pivot charts handle the different areas of your pivot table. In a pivot chart, both the x-axis and y-axis correspond to a specific area in your pivot table: ■

Y-axis—Corresponds to the column area in your pivot table and makes up the y-axis of your pivot chart



X-axis—Corresponds to the row area in your pivot table and makes up the x-axis of your pivot chart

Given this new information, look at the pivot table in Figure 6.5 again. This structure says that the Sales_Period field will be treated as the y-axis because it is in the column area. Meanwhile, the Region field will be treated as the x-axis because it is in the row area.

6

Now suppose you were to rearrange the pivot table to show fiscal periods in the row area and lines of business in the column area, as shown in Figure 6.7. This arrangement generates the pivot table shown in Figure 6.8.

A Few Formatting Limitations Still Exist in Excel 2007 With previous versions of Excel, many users avoided using pivot charts because of the many formatting limitations that came with them. These limitations included the inability to resize or move key components of the pivot chart, the loss of formatting when underlying pivot tables were changed, and the inability to use certain chart types. All these limitations led to pivot charts being viewed by most users as too clunky and impractical to use.

Keeping Pivot Chart Rules in Mind

147

Figure 6.7 This format makes for slightly more difficult reading in a pivot table view but allows your pivot chart to give you the effect you are looking for.

Figure 6.8 With the new arrangement in your pivot table, you get a pivot chart that makes sense.

Excel 2007 brings vast improvements to pivot charts. Users can now format almost every property and component of a pivot chart. In addition, pivot charts in Excel 2007 no longer lose their formatting when the underlying pivot table changes. And as you’ve seen, pivot charts are now (by default) placed on the same worksheet as the source pivot table. Overall, the look and feel of pivot charts in Excel 2007 are very much that of standard charts, making them much more of a viable reporting option. However, a few limitations persist in this version of Excel that you should keep in mind: ■

You still cannot use XY (scatter) charts, bubble charts, or stock charts when creating a pivot chart.



Applied trend lines are often lost when adding or removing fields in the underlying pivot table.

6

Chapter 6

Using Pivot Charts and Other Visualizations



You cannot switch the data source feed from rows to columns (or vice versa) as with a standard chart.



The data labels in the pivot chart cannot be resized.

TIP

148

Although you cannot resize the data labels in a pivot chart, you can change the font of a data label. Making the font bigger or smaller indirectly resizes the data label.

C A S E S T U DY

Creating a Report Showing Invoice Frequency and Revenue Distribution by Product You have been asked to provide both region and market managers with an interactive reporting tool that will allow them to easily see the frequency and distribution of revenues across products.Your solution needs to give managers the flexibility to filter out a region or market if needed. Given the amount of data in your source table and possibility that this will be a recurring exercise, you decide to use a pivot chart. Start by building the pivot chart you see in Figure 6.9. Figure 6.9 The initial pivot table meets all the data requirements.

Next, place your cursor anywhere inside the pivot table and click on Insert. On the Insert tab, you can see the Charts menu displaying the various types of charts you can create. Choose the Column chart icon and select the first 2-D column chart. You immediately see the chart in Figure 6.10.

TIP

6

The next few steps in this case study expose you to some basic chart formatting techniques.To keep the focus of this book on pivot tables, any explanation on the techniques shown here is in the context of this case study. For a detailed look at creating, formatting, and managing charts in Excel 2007, check out Charts and Graphs for Microsoft Office Excel 2007 (ISBN: 0789736101).

Creating a Report Showing Invoice Frequency and Revenue Distribution by Product

149

Figure 6.10 Your raw pivot chart needs some formatting to meet requirements.

The first thing you will notice is that only one of the two data series is visible (the series that represents Sales_Amount). The reason is that the two series are on such different scale ranges that the scale on the bigger series actually represses the other.To fix this problem, you have to place one of the series on a secondary axis. Right-click on the Sales_Amount data series and select Format Data Series. After the Format Data Series dialog box activates, click the Secondary Axis radio button, as demonstrated in Figure 6.11. Figure 6.11 Place the Sales_Amount series on a secondary axis.

6

150

Chapter 6

Using Pivot Charts and Other Visualizations

Next, right-click on the Sales_Amount series again and select Change Series Chart Type. Here, you select the Line with Markers chart type, as illustrated in Figure 6.12. Figure 6.12 Change the chart type for the Sales_Amount data series to a line chart.

At this point, your pivot chart should look similar to the one in Figure 6.13. As you can see, the bars represent the number of invoices generated for each product, and the line represents the revenue for each product. Figure 6.13 All that is required now is some final formatting.

6

Creating a Report Showing Invoice Frequency and Revenue Distribution by Product

151

Now change the data series names to be a bit more user-friendly. Activate the PivotTable Field List and change the names of the data fields in the pivot table from Count of Invoice_Number and Sum of Sales_Amount to something more appropriate. As you can see in Figure 6.14, Invoice Count and Revenue work well in this scenario. Figure 6.14 The names on the data series are now a bit more user-friendly.

On an aesthetic note, try applying one of Excel’s Quick Style designs to your chart.To get to the Quick Style menu, click on the chart and select Design on the Chart Tools ribbon.The idea is to select the style that best suits your taste. As you can see in Figure 6.15, after your style is applied, you have quite the professional-looking chart. Figure 6.15 Applying one of Excel’s Quick Styles gives your pivot chart a professional look and feel.

6

The final step is to remove the line from the Revenue data series. Because this data series does not represent a trend over time, the line between the data points is not necessary and may cause confusion.To remove the line, right-click on the Revenue data series and select Format Data Series.This activates a dialog box where you can specify that no line should be shown for this data series. Figure 6.16 demonstrates how this is done.

152

Chapter 6

Using Pivot Charts and Other Visualizations

Figure 6.16 Remove the line from the Revenue data series to avoid implying that this data point is a trend.

Your final pivot chart should look similar to the one in Figure 6.17. Figure 6.17 Your final report meets all the requirements of content and interactivity.

6

You now have a pivot chart that allows a manager to see the frequency a product is invoiced and the revenue it generates.This pivot chart also gives anyone using this report the ability to filter by region and market.

Examining Alternatives to Using Pivot Charts

153

Examining Alternatives to Using Pivot Charts There are generally two reasons why you would need an alternative to using pivot charts. First, you do not want the overhead that comes with a pivot chart. Second, you want to avoid some of the formatting limitations of pivot charts. In fact, sometimes you might create a pivot table simply to summarize and shape your data in preparation for charting. In these situations, you don’t plan on keeping your source data, and you definitely don’t want a pivot cache taking up memory and file space. In the example in Figure 6.18, you can see a pivot table that summarizes revenue by quarter for each product.

Figure 6.18 This pivot table was created to summarize and chart revenue by quarter for each product.

The idea here is that you created this pivot table only to summarize and shape your data for charting. You don’t want to keep the source data, nor do you want to keep the pivot table with all its overhead. The problem is if you try to create a chart using the data in the pivot table, you inevitably create a pivot chart. This effectively means you have all the overhead of the pivot table looming in the background. Of course, this could be problematic if you do not want to share your source data with end users or you don’t want to inundate them with unnecessarily large files. The good news is there are a few simple techniques that allow you to create a chart from a pivot table, but not end up with a pivot chart. Any one of the following methods does the trick.

Method 1: Turn Your Pivot Table into Hard Values After you have created and structured your pivot table appropriately, select the entire pivot table and copy it. Then select Paste Values from the Insert tab, as demonstrated in Figure 6.19.

NOTE

This action essentially deletes your pivot table, leaving you with the last values that were displayed in the pivot table. These values can subsequently be used to create a standard chart.

This technique effectively disables the dynamic functionality of your pivot chart.That is, your pivot chart becomes a standard chart that cannot be interactively filtered or refreshed.This is also true for method 2 and method 3 outlined next.

6

154

Chapter 6

Using Pivot Charts and Other Visualizations

Figure 6.19 The Paste Values functionality is useful when you want to create hardcoded values from pivot tables.

Method 2: Delete the Underlying Pivot Table

TIP

If you have already created your pivot chart, you can turn it into a standard chart by simply deleting the underlying pivot table. To do this, select the entire pivot table and press the Delete key on the keyboard. Keep in mind that with this method, unlike method 1, you are not left with any of the values that made up the source data for the chart. In other words, if anyone asks for the data that feeds the chart, you don’t have it.

Here is a handy tip to keep in the back of your mind. If you ever find yourself in a situation in which you have a chart but the data source is not available, activate the chart’s data table.The data table lets you see the data values that feed each series in the chart.

Method 3: Distribute a Picture of the Pivot Chart Now, it may seem strange to distribute pictures of pivot chart, but this is an entirely viable method of distributing your analysis without a lot of overhead. In addition to very small file sizes, you also get the added benefit of controlling what your clients get to see.

6

To use this method, simply copy the pivot chart by right-clicking on the chart itself (outside the plot area) and selecting Copy. Then open a new workbook. Right-click anywhere in the new workbook and select Paste Special; then select the picture format you prefer. A picture of your pivot chart is then placed in the new workbook.

Method 4: Use Cells Linked Back to the Pivot Table as the Source Data for Your Chart Many Excel users shy away from using pivot charts solely based on the formatting restrictions and issues they encounter when working with them. Often these users give up the functionality of a pivot table to avoid the limitations of pivot charts.

Examining Alternatives to Using Pivot Charts

155

However, if you want to retain key functionality in your pivot table such as report filters and top 10 ranking, there is a way to link a standard chart to your pivot table without creating a pivot chart. In the example in Figure 6.20, a pivot table shows the top 10 markets by contracted hours along with their total revenue. Notice that the report filter area allows you to filter by business segment so you can see the top 10 markets segment.

Figure 6.20 This pivot table allows you to filter by business segment to see the top 10 markets by total contracted hours and revenue.

Suppose you want to turn this view into an XY scatter chart to be able to point out the relationship between the contracted hours and revenues. You need to keep the functionality of being able to filter out 10 records by model number; however, you want to avoid the inability to create XY. Well, a pivot chart is definitely out because you can’t build pivot charts with certain chart types (such as XY scatter charts). The techniques outlined in methods 1, 2, and 3 are also out because those methods disable the interactivity you need. So what’s the solution? Use the cells around the pivot table to link back to the data you need and then chart those cells. In other words, you can build a mini dataset that feeds your standard chart. This dataset links back to the data items in your pivot table, so when your pivot table changes, so does your dataset. Click your cursor in a cell next to your pivot table, as demonstrated in Figure 6.21, and reference the first data item that you need to create the range you will feed your standard chart. Now copy the formula you just entered and paste that formula down and across to create your complete dataset. At this point, you should have a dataset that looks similar to Figure 6.22. After your linked dataset is complete, you can use it to create a standard chart. In this example, shown in Figure 6.23, you are creating an XY scatter chart with this data. You could never do this with a pivot chart.

6

156

Chapter 6

Using Pivot Charts and Other Visualizations

Figure 6.21 Start your linked dataset by referencing the first data item you need to capture.

Figure 6.22 Copy the formula and paste it down and across to create your complete dataset.

6

Figure 6.24 demonstrates how this solution offers the best of both worlds. You have kept the ability to filter out a particular business segment using the page field, and you have all the formatting freedom of a standard chart without any of the issues related to using a pivot chart.

Using Conditional Formatting with Pivot Tables

157

Figure 6.23 Use your completed linked dataset to create a standard chart.

Figure 6.24 This solution allows you to continue using the functionality of your pivot table without any of the formatting limitations you would have with a pivot chart.

6

Using Conditional Formatting with Pivot Tables One of the most impressive new features of Excel 2007 is the improved conditional formatting functionality. In previous versions of Excel, conditional formatting simply allowed you to dynamically change the color or formatting of a value or a range of cells based on a set of conditions you defined.

158

Chapter 6

Using Pivot Charts and Other Visualizations

In Excel 2007, conditional formatting includes a more robust set of visualizations including data bars, color scales, and icon sets. These new visualizations allow users to build dashboard-style reporting that goes far beyond the traditional red, yellow, and green designations. What’s more, conditional formatting has been extended to integrate with pivot tables. This means that conditional formatting is now applied to a pivot table’s structure, not just the cells it occupies. In this section, you learn how to leverage the magic combination of pivot tables and conditional formatting to create interactive visualizations that serve as an alternative to pivot charts. To start the first example, create the pivot table shown in Figure 6.25.

Figure 6.25 Create this pivot table.

6

Suppose you want to create a report that allows your managers to see the performance of each sales period graphically. You could build a pivot chart, but you decide to use conditional formatting. In this example, let’s go the easy route and quickly apply some data bars. First, select all the Sales_Amount values in the values area. After you have highlighted the revenue for each Sales_Period, click on the Home tab and select Conditional Formatting in the Styles group to data bars, as demonstrated in Figure 6.26. As you can see in Figure 6.27, you now have a set of bars that correspond to the values in your pivot table. This visualization looks like a sideway chart, doesn’t it? What’s more impressive is that as you filter the markets in the report filter area, the data bars dynamically update to correspond with the data for the selected market. How can it be that you did not have to trudge through a dialog box to define the condition levels?

Using Conditional Formatting with Pivot Tables

159

Figure 6.26 Apply data bars to the values in your pivot table.

Figure 6.27 You have applied conditional data bars with just three easy clicks!

6

Excel 2007 has a handful of preprogrammed scenarios that can be leveraged when you want to spend less time configuring your conditional formatting and more time analyzing your data. For example, to create the data bars you’ve just employed, Excel uses a predefined algorithm that takes the largest and smallest values in the selected range and calculates the condition levels for each bar.

160

Chapter 6

Using Pivot Charts and Other Visualizations

Other examples of preprogrammed scenarios include ■

Top Nth Items



Top Nth %



Bottom Nth Items



Bottom Nth %



Above Average



Below Average

NOTE

As you can see, Excel 2007 makes an effort to offer the conditions that are most commonly used in data analysis.

To remove the applied conditional formatting, place your cursor inside the pivot table, click on the Home tab, and select Conditional Formatting in the Styles group. From there, select Clear Rules and then select This PivotTable.

It’s important to note that you are by no means limited to these preprogrammed scenarios. You can still create your own custom conditions. To help illustrate this, create the pivot table shown in Figure 6.28.

Figure 6.28 This pivot shows Sales_Amount, Contracted_Hours, and a calculated field that calculates Dollars per Hour.

6

Using Conditional Formatting with Pivot Tables

161

In this scenario, you want to evaluate the relationship between total revenue and dollars per hour. The idea is that some strategically applied conditional formatting helps identify opportunities for improvement. Start by placing your cursor in the Sales_Amount column. Click the Home tab and select Conditional Formatting. Then select New Rule. This activates the New Formatting Rule dialog box, shown in Figure 6.29.

Figure 6.29 The New Formatting Rule dialog box.

6 The objective in this dialog box is to identify the cells where the conditional formatting will be applied, specify the rule type to use, and define the details of the conditional formatting. First, you must identify the cells where your conditional formatting will be applied. You have three choices: ■

Selected Cells—This selection applies conditional formatting to only the selected cells.



All “Sales_Amount” Cells—This selection applies conditional formatting to all values in the Sales_Amount column, including all subtotals and grand totals. This selection is ideal for use in analyses in which you are using averages, percentages, or other calculations where a single conditional formatting rule makes sense for all levels of analysis.

162

Chapter 6

Using Pivot Charts and Other Visualizations All “Sales_Amount” Cells with the Same Fields: Market: This selection applies conditional formatting to all values in the Sales_Amount column at the Market level only (excludes subtotals and grand totals). This selection is ideal for use in analyses where you are using calculations that make sense only within the context of the level being measured.

NOTE



The words Sales_Amount and Market are not permanent fixtures of the New Formatting Rule dialog box.These words change to reflect the fields in your pivot table. Sales_Amount is used because your cursor is in that column. Market is used because the active data items in the pivot table are in the Market field.

In this example, the third selection (All “Sales_Amount” Cells with the Same Fields: Market) makes the most sense, so click that radio button, as demonstrated in Figure 6.30.

Figure 6.30 Click the radio button next to All “Sales_Amount” Cells with the Same Fields: Market.

6

Using Conditional Formatting with Pivot Tables

163

Next, in the Select a Rule Type section, you need to specify the rule type you want to use for the conditional format. You can select one of five rule types: Format All Cells Based on Their Values—This selection allows you to apply conditional formatting based on some comparison of the actual values of the selected range. That is, the values in the select range are measured against each other. This selection is ideal when you want to identify general anomalies in your dataset.



Format Only Cells That Contain—This selection allows you to apply conditional formatting to those cells that meet specific criteria you define. Keep in mind that the values in your range are not measured against each other when you use this rule type. This selection is useful when you are comparing your values against a predefined benchmark.



Format Only Top or Bottom Ranked Values—This selection allows you to apply conditional formatting to those cells that are ranked in the top or bottom Nth number or percent of all the values in the range.



Format Only Values That Are Above or Below the Average—This selection allows you to apply conditional formatting to those values that are mathematically above or below the average of all values in the selected range.



Use a Formula to Determine Which Cells to Format—This selection allows you to specify your own formula and evaluate each value in the selected range against that formula. If the values evaluate as true, then the conditional formatting is applied. This selection comes in handy when you are applying conditions based on the results of an advanced formula or mathematical operation.

NOTE



Data bars, color scales, and icon sets can be used only when the selected cells are formatted based on their values.This means that if you want to use data bars, color scales, and icon sets, you must select the Format All Cells Based on Their Values rule type.

In this scenario, you want to identify problem areas using icon sets; therefore, you want to format the cells based on their values. Finally, you need to define the details of the conditional formatting in the Edit the Rule Description section. Again, you want to identify problem areas using the slick new icon sets that are offered by Excel 2007. In that light, select Icon Sets from the Format Style dropdown box. After selecting Icon Sets, select 3 Signs from the Icon Style drop-down. This style of icon is ideal in situations in which your pivot tables cannot always be viewed in color. At this point, your New Formatting Rule dialog box should look similar to Figure 6.31. With this configuration, Excel applies the sign icons based on the percentile bands >=67, >=33, and