Counting Ports of Call with a PivotTable

Written by Allen Wyatt (last updated May 9, 2026)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


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.)

At this point there are two ways you can go, depending on your version of Excel. If you are using Excel 2024 or Microsoft 365, you can use the following to provide a list of all the port names:

=SORT(UNIQUE(TOCOL(Ports,1)))

If you are using an older version of Excel, then the list will need to be manually created. The list could 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 port names, in column B, you could add a simple COUNTIFS formula that references the named range you created:

=COUNTIFS(Ports, A22)

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 if you are using Excel 2019 or older.

Of course, you can bypass putting a formula in column B completely, provided you are using Excel 2024 or Microsoft 365. It just takes a slightly different formula in cell A22:

=LET(x,TOCOL(Ports,1),y,SORT(UNIQUE(x)),HSTACK(y,COUNTIFS(Ports,y)))

This single formula provides the port list and the count for each port.

If you absolutely want to use a PivotTable, then you will need 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. Reorganizing Your Data

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, 2021, 2024, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Choosing an Equation Style

You can define styles for different characters used in the Equation Editor. It is not as full-featured as styles in Word, ...

Discover More

Evaluating Formulas

Need a bit of help in figuring out how Excel is evaluating a particular formula? It's easy to figure out if you use the ...

Discover More

Printing Non-Printing Characters

Serious users of Word often display non-printing characters on-screen so they can see them easier. If you want those ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Formatting a PivotTable

You can format PivotTables using either manual formatting or automatic formatting. You need to be careful, however, as ...

Discover More

Excluding Zero Values from a PivotTable

If you are using a data set that includes a number of zero values, you may not want those values to appear in a ...

Discover More

Expanding PivotTable Rows to Sheets

PivotTables are a great way to work with large quantities of data in an intelligent manner. Sometimes, however, you just ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 6?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.