Search code examples
google-sheetsgoogle-sheets-formulaformulaspreadsheetflatten

Listing the number of rows with 2 of 4 cells filled from a row


Imagine I had a sheet like this

People    Alpha    Bravo    Charlie    Delta    Echo    Foxtrot
p1        x                            x
p2        x        x        x
p3                 x                   x        x

etc. How could I make a function that printed the number of people who took 2 of the following: Alpha, Charlie, Echo and Foxtrot

AKA one of these permutations: A & C, A & E, A & F, C & E, C & F, E & F

Heading


Solution

  • try:

    =INDEX(QUERY(SPLIT(FLATTEN(IF(B2:G = "x"; A2:A&"♥"&B1:G1; )); "♥"); 
     "where Col2 is not null"; ))
    

    update 1:

    =SUMPRODUCT((B2:B16<>"")*(E2:E16<>""))
    

    enter image description here

    update 2:

    =QUERY(INDEX(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE({
     IF(B2:C="",,B1:C1&","), 
     IF(REGEXMATCH(D2:D, "- D2$"), D1&"2,", IF(D2:D="",,D1&",")), 
     IF({E2:E, G2:K, M2:O}="",,{E1, G1:K1, M1:O1}&","), 
     IF(REGEXMATCH(P2:P, "- Z$"), P1&",", ), 
     IF(Q2:Q="",,Q1&",")}),,9^9))), ",$", )), 
     "select Col1,count(Col1) where Col1 is not null group by Col1 
      order by count(Col1) desc label count(Col1)''")
    

    enter image description here