Search code examples
google-sheetsgoogle-sheets-formula

I do not understand the error message displayed when I try to use QUERY() function in Google Sheets


I am trying to copy data over from one sheet to another in Google Sheets and I am currently trying to use this query in the second sheet:

=QUERY(FORM!A3:P1090; "SELECT A, C, D, E, F, G, H, I, J, IF(ISBLANK(K), 'TBA', K), L, M, N, O, P ORDER BY D DESC, E DESC")

The first sheet is a Google Form response sheet, queried to the second sheet so that I can apply conditional formatting, sorting, etc...

But when using the query, it gives me an error as follows:

Error Unable to parse query string for Function QUERY parameter 2: PARSE_ERROR: Encountered " "(" "( "" at line 1, column 37. Was expecting one of: "where" ... "group" ... "pivot" ... "order" ... "skipping" ... "limit" ... "offset" ... "label" ... "format" ... "options" ... "," ... "" ... "+" ... "-" ... "/" ... "%" ... "" ... "/" ... "%" ... "+" ... "-" ...

I am unable to understand what this error means; I was intending that if the data from the original K column is blank (a date) it would automatically show "TBA" in the corresponding column in the second sheet.

Here is the original query, without the K blank check, which works.

=QUERY(FORM!A3:P1090; "SELECT A, C, D, E, F, G, H, I, J, K, L, M, N, O, P ORDER BY D DESC, E DESC")

Solution

  • You have to calculate K column first then stack with other columns and then apply QUERY() function. Try-

    =QUERY({Sheet1!A3:J1090,INDEX(IF(ISBLANK(Sheet1!K3:K1090), "TBA", Sheet1!K3:K1090)),Sheet1!L3:P1090}, 
    "SELECT Col1,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col16 ORDER BY Col4 DESC, Col5 DESC")
    

    It seems you ignore B Column. That is reason to select other column individually. If you want all columns then could try * like-

    =QUERY({Sheet1!A3:J1090,INDEX(IF(ISBLANK(Sheet1!K3:K1090), "TBA", Sheet1!K3:K1090)),Sheet1!L3:P1090}, 
    "SELECT * ORDER BY Col4 DESC, Col5 DESC")