I would like to know how to add a weighted average in my pivot table. In fact, I need to do the following calculation: SUM(col1 * col2)/SUM(col2).
I tried to do it by using the calculated field option but when I enter my formula, I just have the following result as an output: SUM((col1 * col2)/col2) which is equal to SUM(col1).
You will need 1 calculated field, and 1 helper column
Helper Column
col3=col1*col2
Calculated field:
CF=Col3/Col1
If you try to do the helper column as a calculated field, it will sum col1 and col2, then multiply them together which results in a meaningless answer
Given you are after the Excel Pivot table version of a weighted average, I think you might find this article useful:
http://excelribbon.tips.net/T007129_Weighted_Averages_in_a_PivotTable.html
The only thing it doesn't mention is what to do if your weighting sums to zero (in which case you will divide by zero). To avoid that ugliness you can use your Pivot table's DisplayErrorString and ErrorString properties, e.g.
oPivot.DisplayErrorString = True
oPivot.ErrorString = "--"
Though obviously that may hide real errors elsewhere in your Pivot table.
Try to use
=SUMPRODUCT(A1:A6, B1:B6)/SUM(B1:B6)
This article may help you: Calculate Weighted Average in Excel by Ted French
Related
I have this table in excel
I want to create a new column where if have a total score let's say of 92 I do an index/match on the table and get it.
I tried this
=INDEX('Risk Assessment Matrix '!I24:I28,1,1,MATCH(111,'Risk Assessment Matrix '!J24:J28,0))
but not working.
Any help please?
Thanks,
Ilias
Assuming a value given is not above 140, you don't even need a 3rd column. Try:
Formula in D2:
=INDEX(A1:A5,MATCH(D1,B1:B5,-1))
If D1 happens to be above 140 an error is returned. You can catch that by nesting the above in =IFERROR(<TheAbove>,"No Match") for example.
Reorder the list so the third column is ascending not descending. and change the >=0 to just 0
Then use:
=INDEX('Risk Assessment Matrix '!I24:I28,MATCH(111,'Risk Assessment Matrix '!K24:K28))
Your INDEX/MATCH looks a bit odd. You wouldn't normally have the "1,1," in there.
Try this:
=INDEX('Risk Assessment Matrix '!I24:I28, MATCH(111,'Risk Assessment Matrix '!J24:J28,0))
This should return "High" (assuming your first column in the table is "I".
Two methods shown:
Pay attention to the order.
An alternate option is the use the new XLOOKUP function.
Although it would require changing the minimum value range from 0 to -9999. An out of range value for non-numeric values of 9999 would also need to be added.
It has the advantage of being easier to read compared to INDEX and MATCH.
=XLOOKUP($D2,$B$2:$B$6,$A$2:$A$6,"Not Found",-1)
The formula looks up the value against a single list of minimum values.
The match_mode (last parameter) is set to -1. This means perform an exact match and if nothing is found return the next smaller item.
How to customize the grand total from sum to percentage of a column 1 without changing the values in column 1?
For Example:- I have a data
Required output should be :-
Grand total of column value 1 = (value 1/ value 2)*100.
You can create a different column with the formula (value 1/ value 2)*100.
You will then need to unpivot/pivot things to get the data in the format which has Dove, Loreal, etc and the new calculation as columns. So you will be able to easily plot them in a matrix.
I won't call this as a solution, but I think this is the most efficient workaround. Let me know if it helps in any way.
These are the individual data points of the data model:
These are the monthly salaries of the employees (obtained using the pivot table from the data model's data):
Each cell will then be used as the Lookup value which will be run through a table.
The lookup value is to be looked up in column A and column B of the table below and if it is matched (within the range), it will return the corresponding value under column C.
I am unable to find any index and match or vlookup functions in the power pivot functionality of excel using measures--which are used to get some analytics on aggregated values on report objects such as pivot tables.
I have found LOOKUPVALUE( <result_columnName>, <search_columnName>, <search_value>[, <search_columnName>, <search_value>]…) which is a DAX function however, the issue here is that I am doing a range lookup and as shown below, I don't know if you can have an array as an argument to the function.
Traditional calculated fields also do not allow arrays in the formulas.
Lookupvalue() only works on a single column lookups because it will return an empty cell if it cannot find a match as shown below:
But when it does find a match using the table below:
It will work just fine:
First, you need to create a measure for Pay:
Total Pay = SUM(Table1[Pay])
It's important to do it as a measure instead of just dropping 'Pay' into a pivot table (this is called an 'implicit measure' and is concidered a bad practice).
Then, let's say your table with pay ranges is named "Pay Ranges". Create another measure:
Returned Value =
CALCULATE(
VALUES('Pay Ranges'[Value To Return]),
FILTER( 'Pay Ranges',
[Total Pay] >= 'Pay Ranges'[Lower Bound] &&
[Total Pay] < 'Pay Ranges'[Upper Bound]
))
Make sure that all these formulas are Measures, not calculated columns.
Also, the formula relies on the correct construction of the ranges. If they overlap, you will get an error.
I have two columns in a pivot table. Count of Work orders, and Sum of the Cost.
I want to insert a calculated field that simply divides the sum of cost by count of work orders to get an average per work order.
When I put I insert a calculated field with the following formula, it yields the total cost, not the average. You'll see the fields are subtotal (cost) and WO#(work order)
And here is what the output looks like in my pivot table.
When you add a calculated field in a pivot table, you need to only add the reference, not a calculation inside of it, so you don't need to add Sum or Count in your definition. However, Excel works calculated fields in a very infuriating manner - first it adds your values and then performs the calculation - if, for example, I have a calculated field that's simply field3=field2/field1, when I want to display the SUM of these values, instead of sum(field3), it does sum(field2)/sum(field1)
I would recommend doing this calculation outside of the pivot.
For example, see my results when I have the following table as input for a pivot
I had the same issue and found the answer I needed. Like the OP, I want to calculate an average -- SUM(field 1) divided by COUNT(field 2) -- but the problem with this is that there are two functions in the same formula (SUM divided by COUNT). As we have seen, using multiple functions in the same calculation produces unintended results.
The key that worked for me was to create a new field (field 3) in the raw data with a formula that assigns a 1 to items I want to count and a 0 to items I don not want to count, so the count of this column is just the sum. In this way, I convert COUNT(field 2) in the denominator to SUM(field 3). So, the result I need is now SUM divided by SUM, same function on top and bottom, which Excel can handle. And luckily for me in this situation, Excel's "infuriating manner" of calculating is exactly what I want.
As Fernando stated, the calculated field should just refer to the field itself; it shouldn't use SUM or COUNT or anything else. The function you want will be applied when you add the field to the pivot table and you choose the function you want.
I set my calculated function to be [field 1 / field 3], with an IF statement to avoid division by 0, and I used the SUM function when I put the calculated field in the pivot table. The end result is SUM(field 1) / SUM(field 3), which equals SUM(field 1) / COUNT(field 2)
Summary:
Restate your formula so that the same function is used on all fields; for example, find a way to restate an average (SUM/COUNT) to be SUM/SUM or COUNT/COUNT, etc.
Add fields to the raw data that will aid in the restated formula; for example, if your restated formula uses a SUM instead of a COUNT, create a new field in the raw data that assigns 1's and 0's so that the sum of this new field is equal to the count of the other field.
Create the calculated pivot field that uses the fields corresponding to the restated formula, including the new field you just created; do not use SUM or COUNT at this point.
Add your calculated field to the data area of the pivot table and choose the function you want; this function will be applied to each field that is referenced in the formula of the calculated field.
Lets say I have an Excel sheet such that:
Column 1 contains salaries
Column 2 contains gender (M/F)
How can I calculate the average salary for females?
=AVERAGE(IF(B1:B10="F",A1:A10))
entered as an array function (ie using Shift-CTRL-Enter rather than just Enter)
Allthough the answer is already answered/accepted I can't resist to add my 2 cents:
Sums and averages normally are displayed at the bottom of a list. You can use the SUBTOTAL() function to calculate sum and average and specify to include or exclude "hidden" values, i.e. values suppressed by a filter. So the solution could be:
create a formula =SUBTOTAL(101,A2:A6) for the average
create a formula =SUBTOTAL(109,A2:A6) for the sum
create an autofilter on the Gender column
Now, when you filter for "F", "M" or all, the correct sum and average will always be computed.
Hope that helps - Good luck
To do it without an array formula just use this:
=SUMIF(B:B,"F",A:A)/COUNTIF(B:B,"F")
Answered question, solid formulas - BUT - beware of conditional averages based on numbers:
In a very similar situation I tried:
"=AVERAGE(IF(F696:F824<0;E696:E824))" (shift control enter) - In English this asked Excel to calculate an average on all numbers in column E if a result in column F was negative (a loss) - e.g. "calculate an average for all items where a loss occured". (no circular reference)
When asked to calculate an average for all items where a gain (x>0) occured, Excel got it right. However, when the conditional average was based on a loss - Excel produced a huge error (7.53 instead of 28.27).
I then opened exactly the same document in Open Office, where Calc got the (correct) answer 28,27 from the same Array formula.
Recalculating the whole thing in steps in Excel (first new column of only losses, new for only gains, new column for only E-values where a loss/gain occured, then a "clean" (unconditional) average calculation, produced the correct values.
Thus, it should be noted that Excel and Open Office produce different answers (and Excel 2007, Swedish language version, gets them wrong) in some cases of conditional averages.
(sorry for my long cautionary tale - but be a bit careful when the condition is a number would be my advice)
You can put filter in top line of your sheet. Then Filter only Fs from Column2, then calculate average of values.
Or you can add additional column with female salaries only.
The formula would be like: =IF(B1 = "Female";A1)
Then you simply calculate average of newly created column.
Salaries gender
2500 M 0 2500*0
2400 F 1 2400×1
2300 F 1 2300×1
sum =2 sum=4700 average=4700/2
Maybe it be complex.