by Allen Wyatt
(last updated April 27, 2019)
Dutch has a worksheet he uses to track all of the cruises he has taken. Each row is one cruise. The left-hand columns contain ship name, departure date, booking number, etc. The ten right-most columns are labeled "Port 1" through "Port 10" to record the ports visited, in order. Nassau, for instance, might be the first stop on one cruise and the third stop on another. Dutch can't figure out a simple, straightforward way to use a PivotTable (as he does, e.g., to see how many times he's cruised on a particular ship, etc.) to see how many times he's visited each port. He wonders if a PivotTable can be used to count the number of times each unique value appears in a range of cells as opposed to a single row or column.
Dutch can solve this problem without even resorting to a PivotTable. This can be done by selecting the cells containing the ports and giving that range a name, such as "Ports." (How you set up a named range has been covered in other ExcelTips.) Then, you can set up a list of all the ports. This could, for instance, be placed on the same worksheet that Dutch is using, or it could be on a different worksheet in the same workbook.
Let's say, for instance, that the port names are in column A, starting below the detailed data in row 22. To the right of the ports, in column B, you could add a simple COUNTIFS formula that references the named range you created:
Copy this down as many cells as necessary, and you will have a count of how many times each port was visited. (See Figure 1.)
Figure 1. Getting a Count of Ports
The downside to this approach, of course, is that you'll need to make sure that the Ports named range refers to the proper range whenever you add new cruises. You'll also need to manually add any ports desired to the port list.
Another approach is to restructure your data. PivotTables are used to analyze the contents of rows and columns, as implied in Dutch's original question about whether a range could be analyzed. So, instead of having 10 columns to track each port of call, you could have multiple rows that define each cruise, with each row being a port of call. (See Figure 2.)
Figure 2. Getting a Count of Ports
With the data in a format such as this, you can easily create a PivotTable based on the contents of the Port column that would show the count for each port visited. Restructuring in this way—with each row being a port visited—makes the data much more conducive to analyzing with a PivotTable.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13625) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
PivotTables are a great way to process huge amounts of data and make sense of that data. If you have a number of ...Discover More
Wish there was a way to define how you want PivotTables formatted before you actually create the PivotTable? You may be ...Discover More
One of the ways you can use PivotTables is to generate counts of various items in a data table. This is a great technique ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.