使用SumProduct

时间:2018-04-27 20:26:02

标签: excel excel-vba excel-formula vba

我们都知道AverageIfs的作用。但是,如果我想根据另一列中的数据将AverageIFs语句转换为加权平均值,该怎么办?假设在主选项卡中,每行在H列中都有一个数量。正如您现在所看到的,我根据C列中的条件对J列中的价格求平均值。问题:每行都有一个唯一的数量因此,基于符合标准的行H中的数量的加权平均值比仅基本平均价格更准确。任何人对如何改变这个公式都有任何想法?

ProductHier Common Name  Total Sls   Total Fct  2017 avg price  2018 avg price
B1B1403A01  ACC - Finished Goods     2,448   2,612   99      118 
B1B1403A02  ACC - Finished Goods     3,143   3,350   165     180 
B1B1403A05  ACC - Finished Goods     709     613     162     152 
B1B1403A06  ACC - Finished Goods     206     150     123     142 
B1B1403A07  ACC - Finished Goods     1,714   1,441   152     142 
B1B1403A08  ACC - Finished Goods     253     295     142     160 
B1B1403A09  ACC - Finished Goods     2,447   2,435   88      98 
B1B1403A11  ACC - Finished Goods     2,334   3,281   149     174 





  =SUMPRODUCT((Master!C2:C5000='Forecast Calc'!D2)*Master!H2:H5000,Master!J2:J5000)/SUMIFS(Master!H:H,Master!C:C,'Forecast Calc'!D2,Master!J:J,"<>0")

1 个答案:

答案 0 :(得分:1)

use SUMPRODUCT divided by a SUMIF:

=SUMPRODUCT((F2:F9="ACC - Finished Goods")*H2:H9,J2:J9)/SUMIFS(H2:H9,F2:F9,"ACC - Finished Goods",J2:J9,"<>0")

enter image description here