Search code examples
google-sheetsgoogle-sheets-formulaarray-formulascount-unique

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!


Solution

  • 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