Easy Filtering Specifications for a PivotTable

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


David has many PivotTables that are filtered by year. In his data there is a separate field for year (values 2021, 2022, 2023, etc., derived via the Year function). He excludes older years in most cases and reports on more recent years. When a new year arrives, it is a tedious process for David to edit every PivotTable and select the most recent year. He wonders if there is a way to specify the selection values for a PivotTable filter so he doesn't need to go through the tedious editing.

Perhaps the easiest way to do this would be to add a single column to the source data for your PivotTable. The column could contain a simple formula that designates whether the row is within the desired range for inclusion in the PivotTable. For instance, if column A contains the transaction date for the row, then you could include the following in the added column:

=YEAR(A2)>YEAR(NOW())-3

The result of the formula is either True or False, depending on whether the transaction is within the previous three years or not. Thus, if this formula is evaluated in 2023, then any transactions within 2021, 2022, and 2023 would return True; all others would be False. Then, within your PivotTable definition you could filter based on the contents of this particular column, thereby ensuring that only those True rows are included in the PivotTable.

If you prefer a macro-based solution, you could easily develop one that examined each of the PivotTables and changed the PivotField named "Year" so that it was equal to a desired year. The following shows how easy it is to make such a change:

Sub ChangePivotYear()
    Dim sht As Worksheet
    Dim pvt As PivotTable
    Dim iYear as Integer

    iYear = 2023     ' Change to desired year
    For Each sht In Worksheets
        For Each pvt In sht.PivotTables
            pvt.PivotFields("Year").ClearAllFilters
            pvt.PivotFields("Year").CurrentPage = iYear
       Next pvt
    Next sht
End Sub

The macro sets the field to 2023; if you want to use a different year, just change what is assigned to the iYear variable. Note, as well, that the macro affects all the PivotTables in the entire workbook.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12571) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

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

Determining the RGB Value of a Color

Excel allows you to fill a cell's background with just about any color you want. If you need to determine the RGB value ...

Discover More

Understanding Monospace Fonts

Monospace fonts allow you to easily achieve a specific "look" with your text or to line up information in a certain way. ...

Discover More

Hiding Grammar Errors

Are you bothered by the green underlines that Word uses to mark potential grammar errors in your document? You can hide ...

Discover More

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!

More ExcelTips (ribbon)

Error in Linked PivotTable Value

Excel allows you to link to values in other workbooks, even if those values are in PivotTables. However, Excel may ...

Discover More

Pointing PivotTables to Different Data

Changing the data source PivotTables go to can be a bit tricky. This tip explains what can happen when you re-point your ...

Discover More

Turning Off Automatic Sorting in PivotTables

Tired of your data being sorted when you create a PivotTable? Excel allows you to specify how the sorting should occur by ...

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 two more than 7?

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.