Use formula in custom calculated field in Pivot Table - excel

In Excel Pivot table report there is possibility for user intervention by inserting "Calculated Field" so that user can further manipulate the report. This seems like best approach compared to using formula on Pivot table data, outside the Pivot table, for many obvious reasons.
"Calculated Field" dialog, looks like this:
and while it's easy to do calculation between available variables (as shown in screenshot) I can't find how to reference range of values for any of available variables.
For example, if for some reason I want to center the data in range A1:A100 I'd use = A1 - AVERAGE(A1:A100) and fill all rows in regular Excel table. But for Pivot table, if I use "Calculated Field" dialog and add new variable with formula: = 'Actual Sales' - AVERAGE('Actual Sales') I get 0 as output.
So my question is how can I reference whole range for 'Actual Sales' variable in "Calculated Field" dialog, so that AVERAGE() will return the average of all targeted cells ?

I'll post this comment as answer, as I'm confident enough that what I asked is not possible.
I) Couple of similar questions trying to do the same, without success:
Pivot Calculated formula: SUM(Field1)/AVG(Field2)
Excel Pivot Table Calculated Field
II) This article: Excel Pivot Table Calculated Field for example lists many restrictions of Calculated Field:
For calculated fields, the individual amounts in the other fields are summed, and then the calculation is performed on the total amount.
Calculated field formulas cannot refer to the pivot table totals or subtotals
Calculated field formulas cannot refer to worksheet cells by address or by name.
Sum is the only function available for a calculated field.
Calculated fields are not available in an OLAP-based pivot table.
III) There is tiny limited possibility to use AVERAGE() and similar function for a range of cells, but that applies only if Pivot table doesn't have grouped cells, which allows listing the cells as items in new group (right to "Fileds" listbox in above screenshot) and then user can calculate AVERAGE(), referencing explicitly every item (cell), from Items listbox, as argument. Maybe it's better explained here: Calculate values in a PivotTable report
For my Pivot table it wasn't applicable because my range wasn't small enough, this option to be sane choice.

Some of it is possible, specifically accessing subtotals:
"In Excel 2010+, you can right-click on the values and select Show Values As –> % of Parent Row Total." (or % of Parent Column Total)
And make sure the field in question is a number field that can be summed, it does not work for text fields for which only count is normally informative.
Source: http://datapigtechnologies.com/blog/index.php/excel-2010-pivottable-subtotals/

Thank you for planting a seed, Cel! I've been struggling with this for hours, finally got it. I was counting a text field, oops, calculation failed.
Created 2 helper columns in my raw data, each resulting in 1 if condition met, 0 if not. Then pulled each into a pivot column, mine are called, "Inbd" (for Inbound), "Back", where "Back" is a return to sending facility, so in reality the total is one trip, not 2 trips, i.e., back is a subset of inbound and not every inbd has a back (obviously). Trying to calculate in the pivot table so I can sort on the field the rate of back to inbound for each sending facility.
For my calculated field I used: =IFERROR(IF(Pvt_Back>0,Pvt_Back/Pvt_Inbd,0),0)
So: if we sent back to sending some number of times greater than 0, divide Back/Inbd to give me a rate; if equal to 0, then 0; if Inbd = 0, then 0 to avoid Div/0 error.
Thanks again!! :)

Pivot table Excel2007- average to exclude zeros
=sum(XX:XX)/count if(XX:XX, ">0")
Invoice USD
Qty Rate(count) Value (sum)
300 0.000 000.000
1000 0.385 385.000
Average Rate Count should Exclude 0.000 rate

Related

Assistance needed pivot table, Countif, Averages, and tons of data

I have a pivot table with employees names, their grand totals of cases worked for the month, the days they worked during the month, and the case counts for each day.
I have them all stacked on top of each other on a sheet for fast viewing.
I created a column to countif Column (A) has a partial text value that matches the month.
In that column (AR) it returns 1 for true and 0 for not true.
I'm trying to create a formula where it sums up the 1s between the 0s.
The picture is horrible due to the size limits.
Basically, I need to count the days the employee worked and find the average case count for the month for each employee.
I can't use the average function in the pivot table because the count is based on IDs.
I tried If statements, and SumIfs.
ATTACHED IS A SAMPLE OF THE FILE I'M WORKING WITH
Picture of the Spreadsheet as requested
Sorry, i'm working on Excel in french. But I hope my answer with the file modified will help u understand what I'm talking about.
Here is your Excel sample with my modifications : Your Excel file that I modified
You can create another pivot table, that uses your previous pivot table as new datasource. But before doing that, make sure the elements of your first column "Claimed by" is repeated, by checking the column option "repeat element labels" like this :
In this new crosstab, you add as columns : the sum of "Case Count" ; and the count of "Days".
After that, you can filter the column "Claimed by" by selecting only elements without the word "total".
Then your average will be obtained simply by dividing the two columns.

How do I create a custom grand total or calculated field in my pivot table in Excel?

I have a pivot table with various calculated fields. I want one of these calculated fields to change depending on what I choose from the slicer. In order to help understand what I'm trying to do I can provide some screenshots:
Here each row contains information for one SITA and each column is a calculated field. The Var(%) column is (ABS(OTB Occupancy - OFF Occupancy))/OTB Occupancy. The very last entry in Var(%) is calculated manually and takes the average of the column (this restricts me from filtering the pivot table as I'll have to recalculate the formula and/or move it to another cell so it stays in the position where it is the last cell).
Now my problem is I am no longer using this pivot table but I am starting to create other pivot tables which need to be more dynamic than this one. For example:
As you can see the first two entries of April in the pivot table correspond with the previous pivot table (OTB Occupancy and OFF Occupancy are the same as Sum of Act_Occ and Sum of Fct_Occ respectively). However, I need the third column to be the average given in the last entry of Var(%). (Please note that this cell isn't part of the pivot table and it's just a formula i used). But also, if I were to select two SITAs only from the slicer I'll want only the average of them two.
I'm not sure if excel can do what I want but any help is appreciated.

How to get percentage answer from pivot data?

Suppose I have the following fields in my Pivot Table:
agent | actual sales
Now I want to add another field which will calculate the percentage of actual sales to the total sales. How do I write the formula for calculated field?
[Edit: ] If you want to do this type of calculation in a calculated field in the Pivot Table, I'm afraid it will not work as you can only access certain variables from such a calculation. It is explicitly stated in the Office Support that "[f]ormulas cannot refer to totals" giving you a hard time to calculate your percentages.
But if you on the other hand will the calculation in a "separate column" you can do it in the sheet below, either using =GETPIVOTDATA("Sum of sales2";$E$3;"agent";E4) or =GETPIVOTDATA("Sum of sales";$E$3;"agent";E4)/GETPIVOTDATA("Sum of sales";$E$3)in the first row of the separate column.
However trivial, my original answer contain the straightforward way:
In Excel 2010 at least, you can in the Value Field Settings dialouge choose to show the values in your actual sales column as "% of Grand Total" among other calculations. Observe that this is not just a formatting, it actually calculates the values:

How to show less than a specific percentage in an Excel pivot table?

I have a pivot table made in Excel and I already have all the % collected data there.
Now, what I need to do is show only the critical ones which are less than 85%, as I don't need anything above that being shown.
Is there a way I can show less than 85% or any other amount in the future?
Add another column to your raw data. Set formula to [assuming the % is in column A]:
=A1<85%
Add this column to your pivot table as a filter. Filter for where your new column = TRUE.
Edit for new info
Per your comments below, the %'s are not actually calculated "within" the pivot table, they are next to the pivot table on the same tab. So, simply add an "if" statement to that formula, like so:
= if(('Total Paid'+'Total Contr. Adj.')/('Total Billed Amount'-'Other Adj.'-'Write-Off')<85%,('Total Paid'+'Total Contr. Adj.')/('Total Billed Amount'-'Other Adj.'-'Write-Off'),"")
This will check to see if your formula is <85%. If it is, the formula will appear there.

Excel pivot table exclude some column totals

I am using an Excel 2010 pivot table to display data. I need the sub totals in most columns but some columns display percentages and totaling the percentages is not correct and displays confusing values. Is there any way I can choose which columns not to total.
It's hard to make sure I'm accurately addressing your question without more detail about your data, but I will provide a simple example.
Recommendation
I would suggest that you put all measures/values in the Values area of the Pivot Table, and not in the Row Labels. That way, you will not get Row sub-totals for values.
In order to address the non-additive totals and sub-totals for your percentages, I recommend that you remove the pre-calculated percentages from your Pivot Table Values and instead use a Calculated Field that is calculated within the Pivot Table itself from the base data, and will provide correct aggregate totals and sub-totals.
Example
See below:
Method
In order to create a Calculated Field using the Ribbon, select your Pivot Table, and then go to PivotTable Tools --> Options --> Fields, Items, & Sets --> Calculated Field.
Then, enter a name for the new Field (CalcPercentSoldUnits in my example below), as well as the formula definition for the field ( =UnitsSold /UnitsProduced in my example below). Click 'Add' to create the field and then 'OK' to exit the dialog box.
Now you have created a derived field not in your base data table, but in your Pivot Table, which can be used just like a normal field. You can also see that it will calculate totals and sub-totals correctly because instead of adding constants, it is calculating based on the sums of other constants from which the percentages are derived.
In some cases depending on how your data is structured, you may need to create a Calculated Item instead of a Calculated Field.
I hope this helps - if this doesn't address your situation, please post additional examples of your data and desired results. Thanks!
I have the same problem. Some Columns should be totaled, and others should not be. The only thing I figured out is to Grand Total all columns, then format those cells in the Grand total so that the font color matches the background color. This hides those selected Grand Totals from being viewed and/or printed. I experimented by expanding the Pivot Table rows, and the formatting for the selected cells followed into the new cell(s) and when I removed some of the rows, the formatting followed as well.
Wherever you don't want to show the total columns simply hide the column in the total section. I couldn't find any other way to do it.
Be careful about things like distinct/unique counts. This method helps with percentages, but you don't want to sum or average or otherwise aggregate unique counts. I would prefer to be able to just exclude a total for a single field but haven't found a method to do so.
I think I have a similar situation and a great answer for presentation purposes. I'm billing a customer for unbilled items; my pivot shows Qty, rate, and total missed revenue (qty*rate) for each month. Having a sum of Qty and Revenue makes sense for each month, but totaling the rates of the items doesn't. Pivot table and value options are an all-or-none solution. Rather, I just selected the totals I needed to hide and formatted them with white font color (blue for the grand total). My pivot table looks great now with this band-aid approach.

Resources