Search code examples
if-statementgoogle-sheetstransposearray-formulasgoogle-sheets-query

How to convert a data matrix (x's and nulls) into relational rows in Google Sheets?


I encountered a problem, where I need to convert a data matrix (with X's and empty cells) into some kind of a list; I have already seen similar questions in here, but I was unable to apply it for my data to work.

This is the matrix I have:

        | A | B | ... | N |
-------------------------------
  1     | x |   | ... | x |
  2     |   | x | ... |   |
  .       .   .   ...   .
  .       .   .   ...   .
  .       .   .   ...   .
  N     | x | x | ... |   |

The columns and rows number can vary.

I want the output table to be like that:

| column1 |  column2 |
-------------------------------
    1           A 
    1           N 
    2           B 
    .           .
    .           .
    .           .
    N           A 
    N           B 

I think it is understandable :) Any help would be appreciated :)

Here is the real data I use: https://docs.google.com/spreadsheets/d/1SlYKMrZy5cyQ7sljTvmiwu6XkIDN_WILDhEM4cWyYnk/edit?usp=sharing


Solution

  • try:

    =ARRAYFORMULA(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
     IF(Sheet1!B3:EM<>"", "♠"&Sheet1!A3:A&"♦"&Sheet1!B2:2&"♦", ))
     ,,999^99)),,999^99), "♠")), "♦"))
    

    enter image description here