How to calculate average using calculated field in Excel Pivot Table? - excel

I have a question concerning calculated fields in Excel Pivot Table.
I have attached an image for perusal.
Observed that in the attached image below, what happened was that I tried to find out using the calculated field in pivot table, the Average Profit Per Genre.
I have summarized both the Sum Of Budget and Sum Of Box Office Revenue to Average Of Budget and Average Of Box Office Revenue respectively.
However, it seems that calculated field won't allow me to minus the Average Of Budget and Average Of Box Office Revenue, so that I can get the Average Profit Per Genre.
It seems that calculated field would only calculate the Sum Of Budget and Sum Of Box Office Revenue.
Would like to ask if there are any other way around this? So that i can find out the Average Profit Per Genre?
Thanks!

Calculated Fields always sum fields, no matter what aggregation you set via the Value Field Settings dialog box.
You can either add your table to the Data Model, i.e. use Power Pivot, or else add a dummy column to your table - named 'Dummy', say - which contains the value 1 in every row. You can then use the following Calculated Field:
= ('Box Office Revenue' - Budget) / Dummy

I see the Excel Pivot Table you are trying to create is from the Hands-On Activity in the Google Professional Certificate in Data Analytics - Course 5.
I have a workaround to solve the problem, though it does not directly address the Calculated Fields issue.
STEP ONE:
As Pivot Table will not allow you to add a column, start typing in Cell D3, the heading of the column as "Average Profit".
In Cell D4, type the formula =C4-D4 (which calculates Average Box Office minus Average Budget = Average Profit). Then fill down from Cell D4 to get Average Profit for each genre.
STEP TWO:
Select the Pivot Table along with column D. Copy and go to cell F3 and click paste. Now, select the range of cells where your data is, from F3 to I20. Go to Sort & Filter and choose "Custom Sort". Make sure "My data has headers" is checked.
SORT BY - Average Profit
SORT ON - Values (leave as default, no need to change)
ORDER - Largest to smallest
You will then find all the genres arranged by Average Profit, which will help you answer the activity's requirement - "Which movie genre generates the most profit on average?"
Hope this helps. Feel free to ask for any clarifications. Thank you and keep going, guys!
P.S. I thought of adding a screenshot, but that might be considered a breach of Coursera Honor Code, as it would have the answer to the activity's requirement!

Related

SubTotal - unable to get the correct value for the fields where avg out the vlaue

I need your help on the below two points:
1) When I subtotal the value based on the allocation key, the fields where i have used avg() to sum up the percentage is not summing up correctly.
2) How can i provide the different color coding for the sub total row and the header in the report.
Please refer the snippet for your easy reference.
Thanks in advance
enter image description here
Coding:-
Avg(If([Qtr]="Q1",[percentage])) as [Q1 %],
Sum(If([Qtr]="Q1",[Total Value $])) as [Q1],
Avg(If([Qtr]="Q2",[percentage])) as [Q2 %],
Sum(If([Qtr]="Q2",[Total Value $])) as [Q2],
There has been an update since 7.11 to allow the user to toggle between calculating values on the underlying data or whats shown in the cell values of the pivot table.
It is now possible to configure the cross table to calculate subtotals
and grand totals based on the aggregated values visualized in the
table, as an option to calculating it using the underlying row level
data. This is useful, for example, when you want to visualize the sum
of the absolute values of the categories displayed in the table:
As far as I know, you cannot do color customization to the Sub or Grand Total rows. You can edit the appearance of the Header row by View > Visual Theme > Edit Custom Theme and modifying the Details Tab. You can also pull in a template from one of the Spotfire Sample Reports that already do it if you want.
https://community.tibco.com/wiki/whats-new-tibco-spotfire?
The 6.5.3 User's Guide says this regarding the first question:
Note: The aggregated value for subtotals is not calculated on the
values shown in the cross table, but on the underlying row values. For
example, if "Average" is used as aggregation measure, the subtotal
average of a column is calculated on the rows the column is based on
and not on the values shown in the cross table.
I believe that "subtotal average" means the average of the rows involved in the calculation. I don't see any way to customize the way that subtotals are calculated.
For your second question, I don't believe that there's a way to do that, unfortunately.

Calculated Field in PowerPivot

I have tried researching this question, but have had issues understanding DAX.
I am using PowerPivot instead of a normal pivot table so that I can use the distinct count feature. I would like to create what in a classic pivot table would equate to a calculated field. I put together an example in the picture below.
In the value section of the pivot table, I have a distinct count of the sales of red hats (column B). To the right also in the value section, I have the count of total hat sales (all colors) (column C). I would like to add another column that displays the red hat sales as a percent of the total hat sales - The solution that I am looking for would divide the 'Distinct Count of Red Hat Sales' over the 'Count of Total Sales' using a field or measure in PowerPivot (Essentially what I have manually entered in column D).
I believe that I am doing to have to use DAX to create a measure?
I am sure that this has probably been answered before, but I have had trouble finding exactly what I am asking. Any help would be greatly appreciated.
You need to create a DAX measure with the following formula:
= DIVIDE( [Count of Red Hats], [Count of Total Hats])
This function ignores division by zero errors. If such errors happen, the function by default displays blanks, but you can choose to display something else (DIVIDE function has third optional parameter).

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:

Excel pivot table - average of calculated sums

I'm sure this is simple, but how do I get a pivot table to display an average for a calculated sum of fields? In the simplified example, I've filtered out fund x1, and the pivot table is showing the sums of the remaining funds per person. Now how do I get an average by person (so, manually calculated, 3300/3)?
I tried using a calculated field, but cannot figure out how it will work because the denominator will change based on how many people will have the funds I'm filtering on. If I use the averaging inside the calculated field it goes back to averaging the funds.
I tried putting the calculation outside the pivot table, and this works, but of course as I filter, my calculated field is no longer adjacent to the pivot table data, instead just floating off on the worksheet by itself.
TIA.
Per request here is the field list - if I try adding an "average of amount" to the value box it averages the fund amounts, instead of the fund amount per person. :
Here is a working solution:
Firstly you should install or enable Power Pivot. Quoting Microsoft:
Power Pivot is an Excel add-in you can use to perform powerful data
analysis and create sophisticated data models.
https://support.office.com/en-us/article/Power-Pivot-Powerful-data-analysis-and-data-modeling-in-Excel-a9c2c6e2-cc49-4976-a7d7-40896795d045?ui=en-US&rs=en-US&ad=US
In newer Excel versions Power Pivot is already installed and you can enable it by going to:
File > Options > Advanced > Data > Enable Data Analysis add-ins: Power Pivot, Power View, and Power Map
Alright, so you have Power Pivot now and you can see Power Pivot tab. Please follow the steps below:
Select your data and click add to “data model” icon on Power Pivot tab.
In Power Pivot window add column which will count distinct number of
persons in the data. =DISTINCTCOUNT([person]) name it for example
“DistPersNo”. This is crucial step – Power Pivot enables you to
count unique values in selected column.
Add another column with formula =[amount]/[DistPersNo] name it
“PersonAverages”.
In Power Pivot window click PivotTable and add new pivot table to
your worksheet.
In Pivot Table add 'persons' to rows and 'amount' to values. Now, if you add 'PersonAverages' to values (sum of it) and filter out fund 'x1' you will achieve desired result i.e. value of 1100.
Hope that helps.
I would add a helper column in column D to count unique customers.
Sort your data by person
In column D2 put =IF(A2=A1, 1, 0) and call the column UniqueCust
Copy formula down your dataset for all rows
Add the column to your pivot
Create a formula in your pivot table called Avg per Cust =Value/UniqueCust
This will flag each row in your data with a 1 if it is the first time a name appears in the column or zero otherwise. The pivot table calculation will sum up the total value and divide by the total unique customers.
I'm assuming that you want the value to come in any pivot table and not in a cell calculated outside the pivot table as a formula.
As a workaround you can use another pivot table, which takes the input as the original pivot table to find the average.
pivot tables
The second pivot table has data source as- E3:F5 or till whatever row you require.
You'll have to refresh all so that the second pivot table reflects any changes in the filter of first pivot table.
I've hidden (or you can filter it out) the grand total in the first pivot table so that the average gives the average of the sum of the amounts.
Since you didn't mention how you are using the data, I will give a couple of options that could work.
If you are the only user of the data or if someone else using the data is pivot table savvy you can use the following field list setups to switch data usage:
Sort by Fund (Note the Fund and Person in the Row labels section)
and Sort by Person (Note the reversed position of Fund and Person in the Row labels section)
To simplify the data, you can always minimize the main fields.
If you are distributing the pivot table to other people who aren't able or willing to modify the pivot table data, I would recommend setting up two separate pivot tables (using the same data source) with the same setups that I showed above.
Click the pivot table to bring up the field list.
In the Values section where it says "Sum of Amount" click the drop down.
Click "Value Field Settings" and choose average from the list in the pop-up.

Use formula in custom calculated field in Pivot Table

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

Resources