0

I'm trying to get a query working and so far this works:

=QUERY({Sheet1!A2:G; 'Sheet2'!A2:G; 'Sheet3'!A2:G;'Sheet4'!A2:G}, "where Col1 is not null order by Col1 asc")

When I add the second condition with an OR I can't get it to work. So far I've tried:

=QUERY({Sheet1!A2:G; 'Sheet2'!A2:G; 'Sheet3'!A2:G;'Sheet4'!A2:G}, "where Col1 is not null OR where Col2 is not 'complete' order by Col1 asc")

or

 =QUERY({Sheet1!A2:G; 'Sheet2'!A2:G; 'Sheet3'!A2:G;'Sheet4'!A2:G}, "where Col1 is not null OR (Col2 != 'complete') order by Col1 asc")

What am I doing wrong?

3
  • The != seems to work but isn't showing results that should meet the conditions. Here is where I'm at after some more tries. =QUERY({Sheet1!A2:G; 'Sheet2'!A2:G; 'Sheet3'!A2:G;'Sheet4'!A2:G}, "WHERE (Col1 is not null) OR (Col2 != 'complete') order by Col1 asc")
    – Jason
    Commented Nov 29, 2017 at 18:59
  • Here is the link to an editable truncated sheet. Formula is in cell A2 of the ToDo sheet and what I'd like it to do is aggregate all the other tabs and sort by date but not pull in any items marked "complete." docs.google.com/spreadsheets/d/…
    – Jason
    Commented Nov 29, 2017 at 20:28
  • Thanks @pnuts. The form is editable by everyone but I did drop it in and got the #VALUE! error.
    – Jason
    Commented Nov 29, 2017 at 21:47

3 Answers 3

1

The where keyword should be used only once.

The not equal operator is <> not !=.

Use parenthesis between conditions

  • instead of Col1 is not null OR (Col2 != 'complete')

  • try (Col1 is not null) OR (Col2 != 'complete')

Reference

Query Language Reference

1
  • Thanks Rubén. The parenthesis around both conditions seems to work but doesn't show any actual results though the conditions should show several items. If I remove the order by clause only results from the first sheet show up and even then those include rows where Col2 is marked complete. So neither of these are working: "WHERE (Col1 is not null) OR (Col2 != 'complete')" --- Shows only results from sheet 1 "WHERE (Col1 is not null) OR (Col2 != 'complete') order by Col1 asc" --- no results
    – Jason
    Commented Nov 29, 2017 at 18:53
0

I ended up completely rewriting the query and using the IMPORTRANGE function which allowed the data filter option from the menu to remove the completed items which was the objective. I couldn't find a solution to a workable 2nd condition with the OR. The below example works. There is probably a more ideal solution but I couldn't get it to work.

  • Use semicolons between data to stack vertically (verses commas which will stack them side by side).
  • Be sure to use where clause "Col1 is NOT NULL" to filter out the empty rows, otherwise, your data will be listed further down on the sheet after the empty rows.
  • The sort function replaces the order by clause.

Here is the final code broken apart for readability

=SORT(
   QUERY({
      IMPORTRANGE("GoogleSheetHash","Sheet1!A2:G");
      IMPORTRANGE("GoogleSheetHash","Sheet2!A2:G");
      IMPORTRANGE("GoogleSheetHash","Sheet3!A2:G");
      IMPORTRANGE("GoogleSheetHash","Sheet4!A2:G")},
      "select * where Col1 is NOT NULL",0
      )
,1,TRUE
)
0

I found this formula to work:

=QUERY(Raw!A2:E, "SELECT A,B,C,D,E WHERE D='Jenn' OR E='Jenn' ",-1)

Replace the following:

Raw!A2:E = Your range
Jenn = Your search criteria

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.