我有一个用于多个条件的AVERAGEIFS公式。对于某些条件对,我希望仅当两个条件都为真时才取平均值。这是我目前的公式:
=AVERAGEIFS('NA Trades'!$R$3:$R$1048576,'NA Trades'!$C$3:$C$1048576,"TSX D3",'NA Trades'!$DW$3:$DW$1048576,">16",'NA Trades'!$Z$3:$Z$1048576,"<20",'NA Trades'!$BB$3:$BB$1048576,"<5.25",'NA Trades'!$AA$3:$AA$1048576,">240000000",'NA Trades'!$BB$3:$BB$1048576,">5.25",'NA Trades'!$CQ$3:$CQ$1048576,"<14.55")
最后4条标准是我想成对链接的标准
我只希望它然后应用'NA Trades'!$ AA $ 3:$ AA $ 1048576,“> 240000000”条件,当'NA Trades'!$ BB $ 3:$ BB $ 1048576,“ <5.25”且仅应用当“ NA Trades”!$ BB $ 3:$ BB $ 1048576,“> 5.25”时,“ NA Trades”!$ CQ $ 3:$ CQ $ 1048576,“ <14.55”标准。 (因此,如果BB> 5.25,则AA> 240000000标准不重要,而当BB <5.25时,CQ <14.55无关紧要)
为此,我在数据集中添加了另一列,以识别标准对何时为真,而仅将其包括在均值中。但是,我试图弄清楚如何在不添加其他列的情况下执行此操作,而仅在AVERAGEIFS本身中执行此操作。我尝试了嵌套和AND来配对条件,但始终遇到错误。
答案 0 :(得分:1)
一个更简洁的选择是切换到数组公式 **:
=AVERAGE(IF('NA Trades'!$C$3:$C$20="TSX D3",IF('NA Trades'!$DW$3:$DW$20>16,IF('NA Trades'!$Z$3:$Z$20<20,IF(IF('NA Trades'!$BB$3:$BB$20<5.25,'NA Trades'!$AA$3:$AA$20>240000000,1),IF(IF('NA Trades'!$BB$3:$BB$20>5.25,'NA Trades'!$CQ$3:$CQ$20<14.55,1),'NA Trades'!$R$3:$R$20))))))
尽管在这种情况下,强烈建议您不要使用整个列引用;因此,我选择的上一行参考值为20(显然,可以根据需要增加参考值,但请确保将其尽可能降低)。
或者,您可以使用SUMIFS
/ COUNTIFS
的组合,虽然不太简洁,但是它的优点是引用整个列几乎不会影响性能:
=SUM(SUMIFS('NA Trades'!$R$3:$R$1048576,'NA Trades'!$C$3:$C$1048576,"TSX D3",'NA Trades'!$DW$3:$DW$1048576,">16",'NA Trades'!$Z$3:$Z$1048576,"<20",'NA Trades'!$BB$3:$BB$1048576,{"<",">="}&5.25,'NA Trades'!$AA$3:$AA$1048576,{">240000000",">=0"},'NA Trades'!$BB$3:$BB$1048576,{"<=",">"}&5.25,'NA Trades'!$CQ$3:$CQ$1048576,{">=0","<14.55"}))/SUM(COUNTIFS('NA Trades'!$C$3:$C$1048576,"TSX D3",'NA Trades'!$DW$3:$DW$1048576,">16",'NA Trades'!$Z$3:$Z$1048576,"<20",'NA Trades'!$BB$3:$BB$1048576,{"<",">="}&5.25,'NA Trades'!$AA$3:$AA$1048576,{">240000000",">=0"},'NA Trades'!$BB$3:$BB$1048576,{"<=",">"}&5.25,'NA Trades'!$CQ$3:$CQ$1048576,{">=0","<14.55"}))
顺便说一句,第1行和第2行中是否存在值,这些值会阻止您为了简化后者而整体引用这些列?如果没有,请使用:
=SUM(SUMIFS('NA Trades'!$R:$R,'NA Trades'!$C:$C,"TSX D3",'NA Trades'!$DW:$DW,">16",'NA Trades'!$Z:$Z,"<20",'NA Trades'!$BB:$BB,{"<",">="}&5.25,'NA Trades'!$AA:$AA,{">240000000",">=0"},'NA Trades'!$BB:$BB,{"<=",">"}&5.25,'NA Trades'!$CQ:$CQ,{">=0","<14.55"}))/SUM(COUNTIFS('NA Trades'!$C:$C,"TSX D3",'NA Trades'!$DW:$DW,">16",'NA Trades'!$Z:$Z,"<20",'NA Trades'!$BB:$BB,{"<",">="}&5.25,'NA Trades'!$AA:$AA,{">240000000",">=0"},'NA Trades'!$BB:$BB,{"<=",">"}&5.25,'NA Trades'!$CQ:$CQ,{">=0","<14.55"}))
致谢
**输入数组公式的方式与使用“标准”公式的方式不同。首先按住CTRL和SHIFT,然后再按Enter,而不是仅按ENTER。如果操作正确,您会注意到Excel在公式周围放置了大括号{}(尽管不要尝试自己手动插入大括号)。