Search code examples
google-sheetsarray-formulascountif

Countifs with array formula to collect data


I have a raw data that contains types of defect (EC,VC,BC,NC).

first type of defect calculation (EC,VC,BC). For example if i want to collect the EC defects, I will collect all the rows that contain EC=0 & if the EC is score down to 0 twice in the same row it will count as 1 EC only in this raw. Same goes for VC & BC.

Second Type of defect calculation (NC) Same calculation of the above but if the NC defect was repeated on the same row it will be summed.

I have the headers containing VC,EC,BC,NC above each column containing the score.

What i need here to calculate each raw containing defects.

I tried the below formula for VC,EC,BC.

=ARRAYFORMULA(IF(ROW(E2:E)=2,"EC",IF(LEN(E2:E)=0,IFERROR(1/0),IF(COUNTIFS($E$1:$BH$1,"EC",$E:$BH,0)>=1,1,0))))

The formula is working without the array formula, but will be hard to drag each time the data is updated.

Also, Tried the below for NC.

=ARRAYFORMULA(IF(ROW(H2:H)=2,"NC",IF(LEN(H2:H)=0,IFERROR(1/0),COUNTIFS($E$1:$BH$1,"NC",$E:$BH,0))))

Sample Sheet: Test Sheet


Solution

  • ={"EC"; ARRAYFORMULA(IF(LEN(TRIM(FLATTEN(QUERY(TRANSPOSE(IF(FILTER(
     INDIRECT("E3:"&ADDRESS(MAX((E:Z<>"")*(ROW(A:A))), COLUMNS(1:1))), 
     E1:1="EC")=0, 1, )),,9^9))))>0, 1, 0))}
    

    ={"VC"; ARRAYFORMULA(IF(LEN(TRIM(FLATTEN(QUERY(TRANSPOSE(IF(FILTER(
     INDIRECT("E3:"&ADDRESS(MAX((E:Z<>"")*(ROW(A:A))), COLUMNS(1:1))), 
     E1:1="VC")=0, 1, )),,9^9))))>0, 1, 0))}
    

    ={"BC"; ARRAYFORMULA(IF(LEN(TRIM(FLATTEN(QUERY(TRANSPOSE(IF(FILTER(
     INDIRECT("E3:"&ADDRESS(MAX((E:Z<>"")*(ROW(A:A))), COLUMNS(1:1))), 
     E1:1="BC")=0, 1, )),,9^9))))>0, 1, 0))}
    

    ={"NC"; ARRAYFORMULA(MMULT(IF(FILTER(
     INDIRECT("E3:"&ADDRESS(MAX((E:Z<>"")*(ROW(A:A))), COLUMNS(1:1))), 
     E1:1="NC")=0, 1, 0), SEQUENCE(COUNTIF(E1:1, "NC"))^0))}
    

    enter image description here