Google-sheets – Count occurrences of names so that only one in each row counts

formulasgoogle sheets

I have a set of data in one Sheet tab, and a counter on another tab in the same document.

I want the counter (in sheet 2) to read through the text in the table in sheet 1, and update how many times one name has occurred, counting only one per line. How would I do this?

I want it to end looking like in sample spreadsheet. Same example here: input data

name1   name2   name3   name4
name3   name5   name2   name2
name1   name2   name3   name3
name4   name1   name4   name2
name5   name3   name5   name1
name2   name4   name1   name5

Output (desired result) is:

name1   name2   name3   name4   name5
5       5       4       3       3

Best Answer

The following formula counts the rows of Data sheet which contain the string given in cell A1 of current sheet:

=countunique(arrayformula(if(Data!$C2:$F = A1, row(Data!$C2:$F), )))

Explanation: the arrayformula replaces each matching string with the row number, and leaves other cells blank. Then countunique counts the number of distinct entries within this array, which is exactly the number of rows.