Occurences of a value, based on corresponding value across columns

时间:2015-04-29 00:18:13

标签: google-sheets count conditional

I currently have a table in a layout similar to this:

Quality | Fruit1 | Fruit2 | Fruit3
----------------------------------
Sweet   | Apple  | Orange | Pear
Firm    | Pear   | Apple  | Watermelon
Sweet   | Orange | Pear   | Melon
Soft    | Banana | Orange | Strawberry
Firm    | Apple  | Melon  | Pear
Sweet   | Melon  | Pear   | Watermelon

(The actual table has many more rows, "qualities" and "fruits", though still only three "Fruit#" columns and the one "Quality" column.)

And am trying to create another table, such that it records (for the above example) the number of occurrences for each fruit per quality:

           |  Firm  |  Soft  | Sweet
--------------------------------------
Apple      | 2      | 0      | 1
Banana     | 0      | 1      | 0
Melon      | 1      | 0      | 2
Orange     | 0      | 1      | 2
Pear       | 2      | 0      | 3
Strawberry | 0      | 1      | 0
Watermelon | 1      | 0      | 1

(The qualities and fruits are deliberately sorted in this table.)

I've tried a number of combinations with VLookup, Match, Index and Countif/s, and I feel like I'm missing something blatantly obvious as nothing has worked as yet.

My thought process for the formula would be something like (in the case of counting Apple occurrences in Firm rows):

  • Check Quality for Firm
  • Check rows with Firm for Apple
  • If an Apple is found, add 1 to the count of Firm:Apple in the output table.

I would also prefer to avoid functions if possible, though I am unaware if this is even possible with the current layouts.

1 个答案:

答案 0 :(得分:0)

根据输出的要求设置行和列标签,并假设Quality在A1中,而Firm用于G1中的输出(使用函数!),请尝试:

=countifs($B:$B,$F2,$A:$A,G$1)+countifs($C:$C,$F2,$A:$A,G$1)+countifs($D:$D,$F2,$A:$A,G$1)  
G2中的

横向和向下复制以适应。