简体   繁体   English

在具有X和Y的列中获取X的计数

[英]Get a count of X in a column that has X and Y

I have a column that has values of X and Y. I want to write a formula in excel that can calculate the number of (x)s and (y)s in the column. 我有一列具有X和Y的值。我想在excel中编写一个公式,该公式可以计算该列中(x)和(y)的数量。 屏幕截图

I've tried using the IF() formula but haven't had much sucess. 我试过使用IF()公式,但没有太多成功。

Your formula should be something like that for D3 : 您的公式应类似于D3的公式:

=COUNTIF(A2:A100, "X")

and for E3 : 对于E3:

=COUNTIF(A2:A100, "Y")

you can use the COUNTIF function: 您可以使用COUNTIF函数:

COUNTIF(range, criteria)

you can learn more about it here 你可以在这里了解更多

so in your example, you can use it like this: 因此,在您的示例中,您可以像这样使用它:

=countif(A:A,"X")

to find the number of X and 找出X

=countif(A:A,"Y")

to find the number of Y . 找出Y的数量。

Just for a variance in the approach, this can be done with an array formula. 仅出于方法的差异,可以使用数组公式来完成此操作。 (Countif is more efficient.) (Countif效率更高。)

=SUM(IF(A2:A8="X",1,0))

In order to let excel know this is an array formula you need to press ctrl-shift-enter after adding the formula. 为了让excel知道这是一个数组公式,您需要在添加公式后按ctrl-shift-enter。

Your formula bar should then look like this: 您的编辑栏应如下所示:

{=SUM(IF(B13:B19="X",1,0))}

The braces "{" and "}" before and after are added by excel automatically. 括号前后的括号“ {”和“}”由excel自动添加。

Array formula can be used to allow normal Excel formula that work on a cell to be applied to a range of cells. 数组公式可用于允许将对单元格起作用的普通Excel公式应用于一系列单元格。

Some references: 一些参考:

http://www.mrexcel.com/articles/CSE-array-formulas-excel.php http://www.mrexcel.com/articles/CSE-array-formulas-excel.php

http://www.dummies.com/how-to/content/how-to-build-an-array-formula-in-excel-2010.html http://www.dummies.com/how-to/content/how-to-build-an-array-formula-in-excel-2010.html

=COUNTIF(B:B,"Y")再次与X相同

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

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