Search code examples
regexgoogle-sheetscountifgoogle-sheets-formulaarray-formulas

Countif and ArrayFormula with multiple levels


I have a formula. It works - but feels like it could be made much simpler.

I have many departments across several columns. Each row has an item that we're tracking and each column has a status text that changes as we do the work.

'queue' - it's in line waiting to be done and weighs down the average

'active' - in process and provides a half value across the average

'done', 'ok'd', 'rcvd' - finished and contributes to the final average 'none' - denotes a department that's inactive on this job and should not count in the final average.

The formula is:

=iferror(((ArrayFormula(sum(countif(B3:O3,{"done","ok'd","rcvd"}))))+(countif(B3:O3,"active")/2))/(counta(B3:O3)-(countif(B3:O3,"none"))),)

The formula works but I'm looking to see if there's an easier way to approach it. Would a query or array modification work better in this scenario?

What if I wanted to add other text strings based on syntax for my current application?

Here's a link to a sample sheet with it in context.

https://docs.google.com/spreadsheets/d/1zPFAcSxM7tYjZmlATYde7qKsDoeH6AW_xjFooOZFOf4/edit#gid=0


EDIT:

As a followup question - how do I get the same thing to work across the columns?

I did some reverse engineering to the solution and can see the formula working across the top of my sheet - but it's giving me an error:

"MMULT has incompatible matrix sizes. Number of columns in first matrix (13) must equal number of rows in second matrix (1)."

Here's the formula I've added (it's also in the linked sheet).

=ARRAYFORMULA(IF(LEN(B4:N4), MMULT(IFERROR(( N(REGEXMATCH(B4:N9, "ok'd|done|ready|rcvd"))+ N(REGEXMATCH(B4:N9, "active"))/2)/MMULT(N(REGEXMATCH(B4:N9, "[^none]")),TRANSPOSE(ROW(B4:B9)^0)), 0), TRANSPOSE(ROW(B4:B9)^0)),))

Solution

  • As a followup question - how do I get the same thing to work across the columns?

    =ARRAYFORMULA(TRANSPOSE(IF(LEN(TRANSPOSE(B4:N4)), MMULT(IFERROR((
     N(REGEXMATCH(TRANSPOSE(B4:N16), "ok'd|done|ready|rcvd"))+
     N(REGEXMATCH(TRANSPOSE(B4:N16), "active"))/2)/MMULT( 
     N(REGEXMATCH(TRANSPOSE(B4:N16), "[^none]")), 
     (ROW(B4:B16)^0)), 0), 
     (ROW(B4:B16)^0)), )))
    

    0