Search code examples
regexgoogle-sheetssummaxarray-formulas

How to count partial matches by row using an arrayformula?


My question expands on what was asked here. (How to use ARRAYFORMULA to count the nb of word for every row)

I want to count partial matches for each row. I've tried using the * as a wildcard but I get big fat zeros returned.
This works if I only want to count exact matches of "NP".
={"NP Count";arrayformula(if(len(A3:A),COUNTIF(if(F3:G="NP",row(F3:F)),row(F3:F)),))}

Columns B:D are hidden.

ID# (A) NP Count(E) Date 1(F) Date 2(G)
12345 1 NP-PM NP
67890 0 NP-PC
24680 2 NP NP

The NP count should be 2, 1, 2.


Solution

  • try:

    =INDEX(MMULT(N(REGEXMATCH(INDIRECT("C2:D"&MAX(ROW(A2:A)*(A2:A<>""))), "NP")), {1;1}))
    

    enter image description here