google-sheets - 带有包含字符和 OR 逻辑的文本的 COUNTIF/COUNTIFS 无法按预期工作
问题描述
我在谷歌表格中有以下列示例,我试图查看有多少人(在 BI 栏中有名字) -如果我选择某些日子,将被排除在外:
A
-----------
s, m
m, w
s, m
所以基本上如果我选择一天f
(星期五)或t
(星期二) - 所有人都无法参加 如果我选择一天f
或w
- 只有一个人能够参加。
遵循文档中的以下示例,括号{}
应该这样做OR
- 但结果根本没有意义
f
或t
=COUNTIF(A1:A3, {"*f*", "*t*"})
- 返回 0m
或s
=COUNTIF(A1:A3, {"*m*", "*s*"})
- 返回 3w
或s
=COUNTIF(A1:A3, {"*w*", "*s*"})
- 出于某种原因返回 1 ( vs 3 )- 但如果我翻转订单 -
s
或w
=COUNTIF(A1:A3, {"*s*", "*w*"})
- 出于某种原因返回 2 ( ?! )
这是怎么回事 ?
它说count items which have the month January or March
(或{"January", "March"}
)
Count Items with Multiple Criteria and Or Logic
In our example, we want to count items which have the month January or March and Product ID 1001 or 1002.
The formula looks like:
=SUM(COUNTIFS(B3:B13, {"1001", "1002"}, C3:C13, {"January", "March"}))
The parameter criteria_range1 is B3:B13 and the criteria1 is the array {“1001”, “1002”}. The parameter criteria_range2 is C3:C13 and the criteria2 is {“January”, “March”}. The result of this COUNTIFS function is 2 numbers, which are number parameters of the SUM function.
解决方案
这一点也不奇怪。与{}
您一起创建一个值数组。由于您可能没有 Excel O365,您会看到返回数组的隐式交集,或者换句话说,第一个值。
在您的示例=COUNTIF(A1:A3, {"*w*", "*s*"})
中,生成的数组{1,2}
因为*w*
只存在一次和*s*
两次。所以这个数组的隐式交集显示你只是1
. 如果您显然交换标准,您会看到2
.
在这种情况下,您通常会使用SUM(COUNTIF(A1:A3, {"*w*", "*s*"}))
return 3
。但请注意,这样做会返回5
for SUM(COUNTIF(A1:A3, {"*m*", "*s*"}))
,因为它的结果数组将为{3,2}
. 因此,在逗号分隔值的情况下,我会选择一些不同的方法。
如果您使用的是 Google 电子表格,可能类似于以下内容:
=IFERROR(QUERY(A:A,"Select Count(A) where A like '%s%' or A like '%x%' label Count(A) ''"),0)
做你想做的事?
推荐阅读
- java - 未来的任务抛出由 IndexOutOfBoundsException 引起的 ExecutionException 而据我所知,我没有使用任何数组
- node.js - “fs 未定义”如何在 VueJS 文件中使用 fs
- jquery - jQuery 调用 MVC 异步方法来加载视图的下拉列表。列表数据未出现。找不到 jQuery $
- python - 无法使用 setup.py 中的 Github Actions 在 Ubuntu 中安装 Tensorflow 2.2.0rc0
- bash - 根据标准输出替换退出代码?
- reactjs - 反应语义 UI 菜单
- javascript - 如何使用 React 将点击事件分配给画布 Api 中的每个圆圈
- javascript - 如何使用更漂亮的配置改进代码格式
- mysql - 使用新列中的前一行值计算每周增长
- php - “while($row = mysqli_fetch_array($result))” 可能为空?