简体   繁体   中英

Pivot Table- Add Percent of the Grand Total

I want to add a calculated filed of percent participation in my Pivot Table using vba. So I want something like this:

Items Sum of Points Percent
First 4 40%
Second 3 30%
Third 3 30%
Total 10 100 %

I thought there is a build in formula and tried to something like this:

 With ptt
    .CalculatedFields.Add name:="value", Formula:=xlPercentOf
    .PivotFields("value").Orientation = xlDataField
    .PivotFields("Sum of value").name = "Percent"
    .PivotFields("Prercent").NumberFormat = "0.00%"
 End With

But i got the same percent value in every row, so its not what I wanted. I will be greatful for any help!

Trying recording macro while creating % with pivot:

在此处输入图像描述

and it returns its script that can hint you some things:

   ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Points"), "Sum of Points2", xlSum    
   With ActiveSheet.PivotTables("PivotTable3").PivotFields("Sum of Points2")
        .Caption = "Percent"
        .Calculation = xlPercentOfTotal
        .NumberFormat = "0.00%"
    End With

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM