Search code examples
google-sheetsgoogle-sheets-formula

Get column name based on cell


I would like to get in column A2:A, the names of columns B1:D1 separated by commas, if the row contains data. As in the screenshot:
enter image description here

I found this formula: =TEXTJOIN(", ",true,BYCOL(B1:D,LAMBDA(c,IFNA(IF(MATCH("?*",c,0),INDEX(c,1),""),""))))
But it takes data from all rows.


Solution

  • You could try ARRAYFORMULA from Google Sheets.

    Example;

    =ARRAYFORMULA(TEXTJOIN(", ", TRUE, IF(B2:D<>"", B1:D1, "")))
    

    From the above code, this ARRAYFORMULA performs an array operation in the specified cell range. Then IF is used to check a cell in the row contains data. If have data, the column name is added to the result. If none, it is ignored.