简体   繁体   中英

How to calculate a pivoted weighted average in Excel?

The data I have is:

Category Name | Item name | Param 1 | Param 2
---------------------------------------------
Category A    | Item 1    | 10      | 20
Category A    | Item 2    | 15      | 25
Category B    | Item 3    | 20      | 30
Category B    | Item 4    | 40      | 35

How can I calculate a pivoted weighted average per items in each Category?

Category A | (10*20+15*25)/(20+25)
Category B | (20*30+40*35)/(30+35)

Insert a helper column after Param 2 headed P1 X P2:-

=C2*D2

Highlight the table and insert a pivot table.

Select Category as row label and sum of Param 2 and sum of P1 X P2 as sigma values.

Now go to Fields, items and sets on the ribbon and create a calculated field called Weighted Average equal to 'P1 X P2'/'Param 2'.

在此处输入图片说明

This should do it for AI believe...
Not tested

=vlookup("Category A", A2:A$5,3)*vlookup("Category A", A2:A$5, 4)+vlookup("Category A", A3:A$5,3)*vlookup("Category A", A3:A$5, 4)//Sumif(D2:D5,"Category A")

Edit: did not notice that you wanted to multiply. Edited with a formula that may work. Not tested and not sure about it.

Assuming you have category in Col A, this array formula will do

Category A { =SUMPRODUCT (IF(A2:A4=A2,C2:C5,""),IF(A2:A4=A2,D2:D5,""))/SUM(IF(A2:A4=A5,C2:C5,"")),}

Just in case you are not aware, for array formula you don't enter the curly braces but enter Ctrl - Shift - Enter and Excel does it

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