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?
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
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.
Recommended Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 3 days 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.· 6 months 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.· 6 months agoHow about Average, Stddev, Max and Min for each field successively?
To post as a guest, your comment is unpublished.· 1 years agoBrilliant!!!! Thank you so much this was amazing!!!
To post as a guest, your comment is unpublished.· 1 years agoSuperB... I've been frustrated with this problem