Google Spreadsheets QUERY() to combine multiple sheets, same workbook

依然范特西╮ 提交于 2019-12-07 00:06:40

问题


Goal: I'm using QUERY() in gSheets to combine data from multiple sheets in the same workbook. The data is an extract from GA broken down into small segments to prevent sampling. This means it has all the same fields, I'm just piecing it back together for analysis.

I would like to use QUERY() to do this because the data is hooked up to auto-update using the Google Analytics Sheets addon. The idea is that when it updates in the future it will piece itself together again and the analysis will run without any additional effort (or risk of human error) on our part.

I followed the Google Support syntax, with one accomodation to fit the multiple sheets. This was mentioned on other posts and seems to work for other people--when combined with IMPORTRANGE referencing outside workbooks, though. There has to be a similar way to do it within the same workbook.

What I've tried:

=QUERY({'LandingPages-Oct1'!A16:F,'LandingPages-Oct2'!A16:F},"select *",0)

^ All comma separation causes the sheets to import side by side

=QUERY({'LandingPages-Oct1'!A16:F;'LandingPages-Oct2'!A16:F},"select *",0)

^ Semicolon separating sheets causes the first sheet of data to appear, but not the second

=QUERY({'LandingPages-Oct1'!A16:F;'LandingPages-Oct2'!A16:F};"select *",0)

^ Semicolon separating query parameters returns no results

What am I missing?

Sample data: https://docs.google.com/spreadsheets/d/1STuBdXPCY-mtJdmKZVblR8WlvLaRPa3tl4Kme10sQBQ/edit?usp=sharing


回答1:


Semicolon separating sheets causes the first sheet of data to appear, but not the second

This usually means you didn't scroll to the bottom of the sheet to see the second part of data there, under all of the empty rows from the first sheet.

Since you probably don't want to import the empty rows, filter them out (by some column that is expected to be nonempty):

={filter('LandingPages-Oct1'!A16:F, len('LandingPages-Oct1'!A16:A));
  filter('LandingPages-Oct2'!A16:F, len(LandingPages-Oct2'!A16:A))}

No need for query at all; query string "select *" means you are not really querying.




回答2:


Alternatively, you can also use query to remove the empty rows

=QUERY({'LandingPages-Oct1'!A16:F; 'LandingPages-Oct2'!A16:F}, "where Col1 <>''")



回答3:


In regards to:

^ Semicolon separating sheets causes the first sheet of data to appear, but not the second

Reason for me why this did not work initially, was that the format of the two tables were not the same. After pasting the same format this worked again.




回答4:


Figured out to how sort by column using the formula above:

=SORT(QUERY({'LandingPages-Oct1'!A16:F; 'LandingPages-Oct2'!A16:F}, "where Col1 <>''"),1,TRUE)

This will sort by column 1.



来源:https://stackoverflow.com/questions/41580887/google-spreadsheets-query-to-combine-multiple-sheets-same-workbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!