Pivot Computation Query

ellyzadg

Board Regular
Joined
May 9, 2016
Messages
75
Hi Everyone,

I would like to ask if there is a way to automatically calculate the percentage between two column in pivot table?
Currently, I am manually computing the % hit (ACTUAL/TARGET).
Thank you!

Legend:

Yellow: Database
Blue: Pivot Table
Red: Manually computed Result


1612256911844.png
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Yes, you can create a calculated item (not Field) using the formula ='Yes'/('Yes'+'No')
 
Upvote 0
Solution
You're creating a calculated Field. You need a calculated item. Select either the No or Yes header cell in your pivot table, then create a calculated item instead.
 
Upvote 0
HI Elly,

I've not used PivotItems (and confess that I couldn't get Rory's solution to work either - but that will be an error I'm making and possibly because I'm using the data model approach).

I adopted a different approach using PowerPivot - it seems more longwinded, but it worked for me:

1. When creating the pivot table ensure that the tick box for 'Add to Data Model' is ticked.
2. Create your pivottable with Date as Rows.
3. Create 4 'measures' by right clicking on the table name in Pivot Table Fields (top box) and selecting Add Measure
1612264034059.png
1612264644536.png


then in the Measures box create each measure: CountHits, CountNo, CountYes and PercentSuccess, which are the Measure Names and the formula's for each are as follows. Note that by selecting 'Category' you can preformat the values.

CountHits: =COUNTA(Table1[Target Hit?])
CountNo: =CALCULATE([CountHits],Table1[Target Hit?]="No")
CountYes: =CALCULATE([CountHits],Table1[Target Hit?]="Yes")
PercentSuccess: =[CountYes]/[CountHits]


1612264109535.png


I then added the three measures: CountNo, CountYes and PercentSuccess to the values area of the pivot table with the following result:

1612264595890.png


Book1
ABCD
3Row LabelsCountNoCountYesPercentSuccess
4Jan1150%
5Feb1100%
6Mar1375%
7Grand Total2571%
Sheet3


Apologies, this is more long winded than Rory's answer, but I think that PowerPivot (with Powerquery) is a very powerful solution - you can mix information even from different source tables.

HTH.
 
Upvote 0
You're creating a calculated Field. You need a calculated item. Select either the No or Yes header cell in your pivot table, then create a calculated item instead.
Hi Rory,

I'm trying to understand the Calculated Item approach, but I can't make it work either. I'd be grateful for your advice. The source data I used is here:

Book1
ABCDE
2Ticket 1Jan31No
3Ticket 2Jan35Yes
4Ticket 3Feb35Yes
5Ticket 4Mar34Yes
6Ticket 5Mar34Yes
7Ticket 6Mar35Yes
8Ticket 7Mar31No
Sheet1
Cell Formulas
RangeFormula
E2:E8E2=IF(D2>=C2,"Yes","No")


I've checked that the data hasn't been added to the data model and was able to Create a Calculated Item. I had added 'Dates' to the Rows area and 'Target Hit?' to the Columns area, with nothing in the Values area. I then clicked on the 'Yes' column heading and added 3 different versions of the formula: When I entered the formula exactly as you've typed 'Yes'/('Yes' + 'No') the apostrophes are removed which is why formulas 2 & 3 are identical.

Book1
ABC
1Calculated Field
2Solve OrderFieldFormula
3
4Calculated Item
5Solve OrderItemFormula
61Formula1= "Yes"/("Yes"+"No")
72Formula2=Yes /(Yes +No )
83Formula3=Yes/(Yes+No)
Sheet5


None of the formula's produced a result.

Book1
HIJKLMN
1Column Labels
2Row LabelsNoYesFormula1Formula2Formula3Grand Total
3Jan
4Feb
5Mar
6Grand Total
Sheet1


1612265462947.png

 
Upvote 0
Hi Peter,

You haven't put a value field in, so you won't see a result - it's got nothing to calculate.
 
Upvote 0
Hi Peter,

You haven't put a value field in, so you won't see a result - it's got nothing to calculate.
Thanks Rory,

I got that to work - though I won't be moving away from PowerPivot anytime soon.

Regards
 
Upvote 0
I would never suggest it! Calculated items are a bit of a last resort really - they're limited and can be slow.
 
Upvote 0

Forum statistics

Threads
1,215,771
Messages
6,126,797
Members
449,337
Latest member
BBV123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top