Google-sheets – How to extract data from a table dynamically

formulasgoogle sheetsgoogle-sheets-arrayformulagoogle-sheets-query

I have the following table

enter image description here

And I would like a formula that would produce the following result

enter image description here

I would like to iterate through the table going from left to right top to bottom and if there is a value in a cell, I would like to return with the matching top row criteria. How would I do this?

Best Answer

=ARRAYFORMULA(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
 IF(C2:O<>"", "♦"&C2:O&"♠"&C1:O1, )),,999^99)),,999^99), "♦")), "♠")))

0