Importing data from multiple sheets with Query/Imp

2019-08-23 05:32发布

I have 2 Google Sheets which track class attendance for our two main sites and each tab on the sheet is a different class/course. Each sheet has a "data" tab which pulls all the class/course data. I am trying to pull the data sheets from these two sheets and put them on a 3rd sheet and organize the class data by a program (GED, CDP, ESL). I have had no issues pulling the data from one sheet, but when I tried stacking the Query and Importrange formulas, I keep receiving an ARRAY LITERAL error that there is a missing row.

My original formula was

={QUERY(IMPORTRANGE("1avE5TJIDVNL7_wqjDLPgocZuecr5Aoz7aI3cI5yIe34", "Data!A3:Ak1000"), "SELECT Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col26, Col27, Col28, Col29 WHERE Col3 CONTAINS 'ESL' AND Col7>0");QUERY(IMPORTRANGE("10q7kBUJVTw62p1cCZjUIR1CsFSev9Ik6q4K-X-RK40Y", "Data!A3:Ak1000"), "SELECT Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col26, Col27, Col28, Col29 WHERE Col3 CONTAINS 'ESL' AND Col7>0")}

and it gave a VALUE error message that the ARRAY LITERAL was missing rows.

Based on other's recommendations from other sites, I tried the formula (below), but received a formula parse ERROR message and tried moving the curly brackets to just around the ImportRange formula, but continued to receive a formula parse ERROR MESSAGE

=QUERY{(IMPORTRANGE("1avE5TJIDVNL7_wqjDLPgocZuecr5Aoz7aI3cI5yIe34", "Data!A3:Ak1000");IMPORTRANGE("10q7kBUJVTw62p1cCZjUIR1CsFSev9Ik6q4K-X-RK40Y", "Data!A3:Ak1000")},"SELECT Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col26, Col27, Col28, Col29 WHERE Col3 CONTAINS 'ESL' AND Col7>0")

I expect that the output will list any classes that contain "ESL" in Col3 and the corresponding columns from both sheets.

1条回答
做自己的国王
2楼-- · 2019-08-23 06:25

understanding ARRAY_LITERAL ERROR:

if both queries output something then all is good:

0

however if one of those queries doesn't have anything to output it outputs #N/A but the issue is that #N/A is only in the 1st cell:

e

but array expects that matrix on both sides to be same (4 columns from both queries):

0

so we wrap each query into IFERROR and in case of error we output fake row with 4 fake columns - {"","","",""} - which will trick the array to output it like:

0

therefore try like this:

=IFERROR(QUERY({IFERROR(QUERY(IMPORTRANGE(
  "1avE5TJIDVNL7_wqjDLPgocZuecr5Aoz7aI3cI5yIe34", "Data!A3:AK1000"), 
  "select Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col26,Col27,Col28,Col29 
   where Col3 contains 'ESL' 
   and Col7>0", 0), {"","","","","","","","","","",""});
  IFERROR(QUERY(IMPORTRANGE(
 "10q7kBUJVTw62p1cCZjUIR1CsFSev9Ik6q4K-X-RK40Y", "Data!A3:AK1000"), 
  "select Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col26,Col27,Col28,Col29 
   where Col3 contains 'ESL'
   and Col7>0", 0), {"","","","","","","","","","",""})}, 
  "where Col1 is not null", 0))
查看更多
登录 后发表回答