Nhong
Nhong

Reputation: 109

How to use COUNTUNIQUE function within ArrayFormula and get a range result?

I have tried to use a COUNTUNIQUE function within ArrayFormula in cell 'A2' to get a result in the range like a column B that I've set a function cell by cell. But it returns only a single value. This is my formula in cell 'A2':

=ArrayFormula(COUNTUNIQUE(D2:D7,E2:E7,F2:F7,G2:G7,H2:H7))

Any help will be greatly appreciated!

Upvotes: 4

Views: 2474

Answers (2)

oshliaer
oshliaer

Reputation: 4979

This problem has interested me for a while. Basically, the solution from @player0 seems obvious to me. But it is difficult to read.

Perhaps using combined arrays and implicit endings search is more appropriate:

=INDEX(
  COUNTIF(
    UNIQUE(FLATTEN(
      {"" & ROW(C2:Z), ROW(C2:Z) & "-" & C2:Z}
    )),
    ROW(C2:Z7) & "-*"
  ) - 1
)

enter image description here

Upvotes: 1

player0
player0

Reputation: 1

you can do it like this:

=ARRAYFORMULA(QUERY(UNIQUE(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
 IF(D2:K<>"", "♦"&ROW(A2:A)&"♥"&D2:K, )),,999^99)),,999^99), "♦")), "♥"))),
 "select count(Col1) where Col1 is not null group by Col1 label count(Col1)''", 0))

0

or like this:

=ARRAYFORMULA({
 COUNTUNIQUE(D2:H2);
 COUNTUNIQUE(D3:H3); 
 COUNTUNIQUE(D4:H4);
 COUNTUNIQUE(D5:H5);
 COUNTUNIQUE(D6:H6);
 COUNTUNIQUE(D7:H7)})

0

Upvotes: 0

Related Questions