简体   繁体   English

COUNTIFS具有来自单元格引用的多个条件(尝试使用数组)

[英]COUNTIFS with multiple criteria from cell references (trying to use an array)

First time I've asked a question, so please bear with me. 第一次我问一个问题,请耐心等待。

I have a formula (in Excel 2013): 我有一个公式(在Excel 2013中):

=SUM(COUNTIFS(Data[Location],{76,876},Data[Difference],"<=2",Data[Year],2017))  

It's counting how many tasks at a particular location have been done within 2 weeks, by two different teams at that location, identified as 76 and 876, with all the data stored in a table imaginatively named Data. 它计算由两个不同的团队在一个特定的位置在两个星期内完成了多少任务,该团队分别标识为76和876,所有数据存储在一个表中,该表被形象地命名为Data。 And it works fine. 而且效果很好。

However, I'd like to be able to do this with many different teams, all identified by a number in another range. 但是,我希望能够与许多不同的团队合作,这些团队都由另一个范围内的数字来标识。 If I just wanted one team from each location, I could 如果我只想从每个地点派一个团队,我可以

=SUM(COUNTIFS(Data[Location],A2,Data[Difference],"<=2",Data[Year],2017))  

but I can't (as far as I can tell?) ask it to look for multiple locations with cell references, like {A2,B2}. 但我不能(据我所知?)要求它查找带有单元格引用的多个位置,例如{A2,B2}。

Is there any way around this? 有没有办法解决? Or should I just add a helper column in my Data table which would link 76 and 876 (and every other pair of teams at the same location)? 还是我应该在数据表中添加一个帮助列,以链接76和876(以及同一位置的所有其他团队)? I'm wary of doing that, because there's a lot of entries in that table, and a lot of helper columns; 我对此很警惕,因为该表中有很多条目,并且有很多帮助器列。 every new formula adds extra calculating time, and it's already weighty enough that I can comfortably make a cup of tea in the time it takes to calculate the book. 每个新公式都增加了额外的计算时间,而且已经很重,我可以在计算书本的时间里舒适地冲一杯茶。

Many thanks. 非常感谢。

minor edit : I realise that in the second line of code, I wouldn't need the SUM function, copypaste error, sorry 小修改 :我意识到在第二行代码中,我不需要SUM函数,复制粘贴错误,对不起

Array literals like {76,876} are only possible using literal values not using references, that's right. {76,876}这样的数组文字只能使用文字值而不使用引用,是正确的。 But if A2 contains 76 and B2 contains 876 , then A2:B2 will be the same as {76,876} if this reference is in array context. 但是,如果A2包含76B2包含876 ,则如果此引用在数组上下文中,则A2:B2将与{76,876}相同。

So in your case and if A2 contains 76 and B2 contains 876 , you could using: 因此,在您的情况下,如果A2包含76B2包含876 ,则可以使用:

{=SUM(COUNTIFS(Data[Location],A2:B2,Data[Difference],"<=2",Data[Year],2017))}

This is an array formula. 这是一个数组公式。 Input it into the cell without the curly brackets and then press [Ctrl]+[Shift]+[Enter] to confirm. 将其输入到没有大括号的单元格中,然后按[Ctrl] + [Shift] + [Enter]确认。 The curly brackets then appear automatically. 大括号然后自动出现。

Or you could using SUMPRODUCT since SUMPRODUCT will have all of it's parameters in array context without explicitly pressing [Ctrl]+[Shift]+[Enter] to confirm. 或者,您可以使用SUMPRODUCT因为SUMPRODUCT将在数组上下文中拥有所有参数,而无需明确按[Ctrl] + [Shift] + [Enter]进行确认。

=SUMPRODUCT(COUNTIFS(Data[Location],A2:B2,Data[Difference],"<=2",Data[Year],2017))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM