如何将COUNTIF与OR结合使用

问题描述 投票:14回答:3

在Google Spreadsheets中,我需要在具有多个条件的范围内使用COUNTIF函数。所以在下表中,我需要像=COUNTIF(B:B,"Mammal"or"Bird")这样的东西并返回值4。

A         |B
-------------------
Animal    | Type
-------------------
Dog       | Mammal
Cat       | Mammal
Lizard    | Reptile
Snake     | Reptile
Alligator | Reptile
Dove      | Bird
Chicken   | Bird

我尝试了很多不同的方法而没有运气。

google-sheets formula countif
3个回答
25
投票

一种选择:

=COUNTIF(B:B; "Mammal") + COUNTIF(B:B; "Bird")

根据文件:

笔记

COUNTIF只能使用单一标准执行条件计数。要使用多个条件,请使用COUNTIFS或数据库函数DCOUNTDCOUNTA

COUNTIFS:此功能仅适用于new Google Sheets

例:

=DCOUNTA(B:B; 2; {"Type"; "Mammal"; "Bird"})

3
投票

您还可以在SUM(COUNTIFS())构造周围使用ArrayFormula:

=ArrayFormula(SUM(COUNTIF(B:B,{"Mammal", "Bird"}))

Source: Google Docs Product Forum


1
投票

你可以像这样使用正则表达式:

=ARRAYFORMULA(SUM(N(REGEXMATCH(B:B, "Mammal|Bird"))))

0

© www.soinside.com 2019 - 2024. All rights reserved.