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?
- 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.
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:
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:
3. And then click OK to close this dialog, and you can see your Count function has been changed to Sum function, see screenshot:
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.
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:
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.
You are guest
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 7 months agoThank you so much for the VBA code, I LOVE it!
To post as a guest, your comment is unpublished.· 2 years agoThank you. The code worked beautifully and saved me a lot of wasted time and energy!
To post as a guest, your comment is unpublished.· 2 years agoI'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.· 2 years agoHow about Average, Stddev, Max and Min for each field successively?
To post as a guest, your comment is unpublished.· 3 years agoBrilliant!!!! Thank you so much this was amazing!!!
To post as a guest, your comment is unpublished.· 3 years agoSuperB... I've been frustrated with this problem
To post as a guest, your comment is unpublished.· 3 years agoAmazing - 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.· 3 years agoThis 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.· 3 years agoChange 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.· 3 years agoJust 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.· 4 years agohi
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?
To post as a guest, your comment is unpublished.· 3 years agodid you ever get a reply to this? I have the same question
To post as a guest, your comment is unpublished.· 4 years agoThanks 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.· 1 years agoKelsey, 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()
Dim xPF As PivotField
Dim WorkRng As Range
Set WorkRng = Application.Selection
.ManualUpdate = True
For Each xPF In .DataFields
.Function = xlStDev
.NumberFormat = "#,##0"
.ManualUpdate = False
To post as a guest, your comment is unpublished.· 3 years agoKelsey- 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.· 4 years agoHi 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.· 4 years agoThis is so useful. This problem has bothered me for years and now its solved.
To post as a guest, your comment is unpublished.· 4 years agoHi,
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,
To post as a guest, your comment is unpublished.· 5 years agoThank 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.
To post as a guest, your comment is unpublished.· 6 years agoHi,
The tips and VB macros is really helpful.
To post as a guest, your comment is unpublished.· 4 years agoGood 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