Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to change multiple field settings in pivot table?

When you create a pivot table in a worksheet, after dragging the fields to the Values list in the PivotTable Field List, you may get all the same Count function as following screenshot shown. But now, you want the Sum of function to replace the Count of function at once, how could you change the calculation of multiple pivot table fields at once in Excel?

doc-change-field-setting-1

Change the field settings in pivot table manually one by one

Change multiple field settings in pivot table with VBA code

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

arrow blue right bubble Change the field settings in pivot table manually one by one


In Excel, you can change the calculation of the field settings by changing the function one by one in the Value Field Settings dialog, please do as this:

1. Select a field in the Values area for which you want to change the summary function in the pivot table, and right click to choose Value Field Settings, see screenshot:

doc-change-field-setting-1

2. Then in the Value Field Settings dialog box, select one type of calculate which you want to use under the Summarize Value By tab, see screenshot:

doc-change-field-setting-1

3. And then click OK to close this dialog, and you can see your Count function has been changed to Sum function, see screenshot:

doc-change-field-setting-1

4. Repeat the above steps to change other fields’ calculation settings one by one.

Note: You can also change the field settings by right click one field cell and choose Summarize Values by and select one calculation you need from context menus.

doc-change-field-setting-1


arrow blue right bubble Change multiple field settings in pivot table with VBA code

The above method will be time consuming and tedious if there are lots of field calculations needed to be changed, here, I can introduce you a code to change multiple filed settings at the same time.

1. Click any cell in your pivot table.

2. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Change multiple field settings in pivot table

Public Sub SetDataFieldsToSum()
'Update 20141127
Dim xPF As PivotField
Dim WorkRng As Range
Set WorkRng = Application.Selection
With WorkRng.PivotTable
   .ManualUpdate = True
   For Each xPF In .DataFields
      With xPF
         .Function = xlSum
         .NumberFormat = "#,##0"
      End With
   Next
   .ManualUpdate = False
End With
End Sub

4. Then press F5 key to execute this code, and all the field settings in your selected pivot table have been converted to your need calculation at once, see screenshots:

doc-change-field-setting-1
-1
doc-change-field-setting-6

Note: In the above code, you can change the Sum function to any other calculations, such as Average, Max, Min as you want. You just need to change the Sum in these scripts: Public Sub SetDataFieldsToSum() and .Function = xlSum to other functions.


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Brian · 6 months ago
    Thank you. The code worked beautifully and saved me a lot of wasted time and energy!
  • To post as a guest, your comment is unpublished.
    Rich · 1 years ago
    I've used the VBA solution with great success in the past, but it doesn't work with the data model. Do you know if there is a solution for that?
  • To post as a guest, your comment is unpublished.
    pierrr · 1 years ago
    How about Average, Stddev, Max and Min for each field successively?
  • To post as a guest, your comment is unpublished.
    Tarryn · 1 years ago
    Brilliant!!!! Thank you so much this was amazing!!!
  • To post as a guest, your comment is unpublished.
    Harendra Singh Kuntal · 1 years ago
    SuperB... I've been frustrated with this problem
  • To post as a guest, your comment is unpublished.
    Sonia · 1 years ago
    Amazing - I am no hot shot with VBA and feel like a champion - this has been driving me crazy for a long time! Thank you
  • To post as a guest, your comment is unpublished.
    Danny · 2 years ago
    This is incredible. I've been frustrated with this problem for years, with some docs with 50+ fields. This is such a time saver!
  • To post as a guest, your comment is unpublished.
    Karishma · 2 years ago
    Change Multiple Field Settings In Pivot Table With VBA Code


    Amazing! Thank you so much. So helpful with my work.
  • To post as a guest, your comment is unpublished.
    John · 2 years ago
    Just what I was looking for !!

    Right after the .NumberFormat line, I added a rename for the column heading in the pivot, so I did not have "Sum of" in all of them.


    .Caption = " " & xPF.SourceName


    Thanks again !!
  • To post as a guest, your comment is unpublished.
    Zoltan · 2 years ago
    hi
    this is very useful thanks for that.
    im just wondering is it possible to set just a few or specific columns's value field settings?
    i mean for example i have values in the first 20 columns and i want to see the data in SUM but from 21th columns comes another type of data (for example distribution) and from that column I would like to see the data in MAX value.
    so is it possible somehow find for example the name of the header and if "distribution" is there change every "distribution" columns into MAX value.
    does it make sense?
    cheers
    Zoltan
    • To post as a guest, your comment is unpublished.
      lorbas · 2 years ago
      did you ever get a reply to this? I have the same question
  • To post as a guest, your comment is unpublished.
    Kelsey · 2 years ago
    Thanks for this! Is there any way to use StdDev instead of Sum? I was able to change your code for Average & Count, but I can't get StdDev to work. Thanks!
    • To post as a guest, your comment is unpublished.
      Gary ODriscoll · 3 months ago
      Kelsey, I just created a macro and changed one manually and then checked the macro code in VBA. To get StdDev to Work use StDev. Code becomes the following:


      Public Sub SetDataFieldsToStDev()
      'Update 20141127
      Dim xPF As PivotField
      Dim WorkRng As Range
      Set WorkRng = Application.Selection
      With WorkRng.PivotTable
      .ManualUpdate = True
      For Each xPF In .DataFields
      With xPF
      .Function = xlStDev
      .NumberFormat = "#,##0"
      End With
      Next
      .ManualUpdate = False
      End With
      End Sub
    • To post as a guest, your comment is unpublished.
      Matt · 1 years ago
      Kelsey- did you get an answer for this or figure this out? I tried to edit the code but have not been able to figure it out yet. I was not sure if there was a way to quickly change it for the different summation options. Thanks!
    • To post as a guest, your comment is unpublished.
      Michelle · 2 years ago
      Hi Kelsey - I'm wondering if you ever received an answer to this? I am trying to do the same thing. Thanks!
  • To post as a guest, your comment is unpublished.
    daniel read · 2 years ago
    This is so useful. This problem has bothered me for years and now its solved.
  • To post as a guest, your comment is unpublished.
    Jani · 3 years ago
    Hi,
    Thank you for the very good solution! Is it possible to make it automatic? So whenever I add a new Field to the values this macro should run.
    thank you in advance,
    Jani
  • To post as a guest, your comment is unpublished.
    Zwakele · 3 years ago
    Thank you for the solution.
    For reason I get an error on the .NumberFormat = "#,##0". I am changing from Sum to Average which works fine but I also want to change the NumberFormat to Number with 1 decimal.

    Thanks
  • To post as a guest, your comment is unpublished.
    Prasenjit · 4 years ago
    Hi,

    The tips and VB macros is really helpful.
    Thanks
    • To post as a guest, your comment is unpublished.
      Suhail Aboobacker · 2 years ago
      Good Day,

      Wonderful. It really helps a lot.
      Your Pivot tips are so wonderful
      I am looking for years and i got real help
      How can we add function for decimals also.
      Thanks a lot