简体   繁体   English

如何计算电子表格中的单元格对

[英]How to count pairings of cells in spreadsheet

Let's say I have a spreadsheet that has two columns of data. 假设我有一个包含两列数据的电子表格。 For example: 例如:

A    B
1    2
2    3
1    1
1    2
1    3
2    3
2    1 

How could I count the total number of times each pair appears in the spreadsheet. 我如何计算每对在电子表格中显示的总次数。 In the example above, 1-2 should have a count of 3 (1 for 2-1, 2 for 1-2), 2-3 should have a count of 2etc 在上面的例子中,1-2应该有3个(1个为2-1,2个为1-2),2-3个应该有2个计数

Note that for Excel versions >2007 , you can use the new formula COUNTIFS : 请注意,对于Excel版本> 2007 ,您可以使用新公式COUNTIFS

[EDIT] Added the correct solution (credits to Chris Nielsen - see the comments) [编辑]添加了正确的解决方案(信用克里斯尼尔森 - 见评论)

=COUNTIFS($A$1:$A$12,A1,$B$1:$B$12,B1) + COUNTIFS($A$1:$A$12,B1,$B$1:$B$12,A1)

One way would be to use a SUMPROUDUCT in column C. That would give you a count of the number of times the combination in that row is encountered. 一种方法是在C列中使用SUMPROUDUCT。这将为您计算遇到该行中组合的次数。

=SUMPRODUCT(--($A$1:$A$7=A1),--($B$1:$B$7=B1))+SUMPRODUCT(--($A$1:$A$7=B1),--($B$1:$B$7=A1))

Following your example this would output: 按照你的例子,这将输出:

A   B   C
1   2   3
2   3   2
1   1   1
1   2   3
1   3   1
2   3   2
2   1   3

SUMPRODUCT can be tricky, you can read some good howtos here: SUMPRODUCT可能很棘手,你可以在这里阅读一些好的方法:

http://chandoo.org/wp/2009/11/10/excel-sumproduct-formula/ http://chandoo.org/wp/2009/11/10/excel-sumproduct-formula/

Jesse 杰西

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

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