Search code examples
google-sheetsgoogle-sheets-formulagoogle-query-language

How to stack different columns from a query into one single column Google Sheets


I have done a QUERY from an importxml in Google Sheets, and I'm getting results in several columns. I need to get these results in only one column, but I always need to keep the first cell of each row even if it's blank. If that's the case, I don't want to keep blanks for other cells in the same row.

My data looks like this:

empty row
empty row
1x 1x 1x

1x 1x 1x
empty row
empty row
1x 1x 1x

1x 1x 1x
empty row
5x

And I want to get:

empty cell

empty cell
1x

1x

1x

1x

1x

1x

empty cell

empty cell

5x

My current code is this: =QUERY(importxml('url-address';"//ul[@class='xxxxxxx']");"SELECT * WHERE Col1 CONTAINS 'x' OR Col1 IS NULL";-1)

EDIT: This is the link to the actual spreadsheet: https://docs.google.com/spreadsheets/d/1ZownNdUfFEeBmZ4hEQwkDVu-phYzU-2nCAH2Fg91GRs/edit?usp=sharing

I'm using to retrieve information for a videogame. I had already done it, but something has changed in the website I get the information from, and therefore now I need to adapt my formulae.

In tab "Gear components" you can find the structure of the data as it was with my previous formulae. In tab 'Formulas', you can find what I'm getting now. The list of gear on the left, and the amount of each one on the right, but with an inappropriate structure. Therefore, I need to keep all 1x and 5x.


Solution

  • I ended up solving this with a different approach. I wrote the IMPORTXML better so I could really retrieve the data I needed, then used a CONCATENATE and a TRANSPOSE to get the data in the format I wanted.