Importing data from multiple sheets with Query/ImportRange formula returning ARRAYLITERAL ERROR

余生长醉 提交于 2019-12-11 19:04:22

问题


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:


understanding ARRAY_LITERAL ERROR:

if both queries output something then all is good:

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:

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

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:

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))


来源:https://stackoverflow.com/questions/56838528/importing-data-from-multiple-sheets-with-query-importrange-formula-returning-arr

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