Search code examples
if-statementgoogle-sheets-formulatransposeflattengoogle-query-language

Join column header with array n times


I am looking to join column headers with their respective arrays any number of times depending on if the cell is not empty and if it has a checkbox.

Link to sheet

enter image description here

I have a formula close but I can't get it to repeat for the array with the respective values.

=JOIN(", ",ARRAYFORMULA(QUERY(TRANSPOSE($A$2:$3),"SELECT Col2 WHERE Col1 = FALSE AND Col2 IS NOT NULL")&"-"))&" : "&JOIN(", ",ARRAYFORMULA(QUERY(TRANSPOSE($A$2:$3),"SELECT Col2 WHERE Col1 = TRUE AND Col2 IS NOT NULL")&"-"))

This needs to be dynamic, meaning that if I add a new column header and values in column D it includes that set. Along with an infinite number of rows, however the rows sizes will always match. Any ideas would be appreciated!


Solution

  • use:

    =ARRAYFORMULA(FLATTEN(QUERY(TRANSPOSE(REGEXREPLACE({
     FLATTEN(QUERY(TRANSPOSE(FILTER(A3:C3&"-"&A4:C8, A2:C2=FALSE)&","),,9^9)), 
     IFERROR(SEQUENCE(ROWS(A4:C8))/0, ":"), 
     FLATTEN(QUERY(TRANSPOSE(FILTER(A3:C3&"-"&A4:C8, A2:C2=TRUE)&","),,9^9))}, 
     ",$", )),,9^9)))
    

    enter image description here