Search code examples
if-statementgoogle-sheetsgoogle-sheets-formulagoogle-sheets-querygoogle-query-language

How to add a WHERE function to a complex string


I am trying to only query data that has a number > 0 in Column K within this complex string.

=QUERY('Form Responses 1'!A1:K,"SELECT *" & if(COUNTBLANK('Helper Formulas'!A1:A3)=3,""," WHERE " & TEXTJOIN(" AND ",TRUE,'Helper Formulas'!A1:A3)),1)

I tried...

=QUERY('Form Responses 1'!A1:K,"SELECT * WHERE K > 0" & if(COUNTBLANK('Helper Formulas'!A1:A3)=3,""," WHERE " & TEXTJOIN(" AND ",TRUE,'Helper Formulas'!A1:A3)),1)

But keep getting an error.

Not sure what I need to do.


Solution

  • try:

    =QUERY('Form Responses 1'!A1:K, 
     "where K > 0"&IF(COUNTBLANK('Helper Formulas'!A1:A3)=3,,
     " and "&TEXTJOIN(" and ", 1, 'Helper Formulas'!A1:A3)), 1)