简体   繁体   中英

COUNTIF based on adjacent cell - Google Sheets

I need a function in Google Sheets similar to SUMIF which counts non numeric values (text), which separates criteria from counted range.

In column 2 below, I need to count all words with their respective activity ID (column 1).

So something like COUNTIF($A2:$A, 1, $B2:$B) . Unfortunately, COUNTIF doesn't take a third parameter.

So below, COUNTIF for activity 1 would be 3 since there are three value cells with activity 1 . For activity 2 , it would be 2.

NOTE : I've tried something like =IF($A2:$A=1, COUNTA($B2:$B),"") , but this just counts all text values in range regardless of criteria of adjacent cell.

在此处输入图片说明

=QUERY(A2:B, "select A, count(A) where A is not null group by A label A 'ID'", 0)

如果您只想使用纯计数:

=QUERY(A2:B, "count(A) where A is not null group by A label count(A)''", 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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