Search code examples
google-sheetsgoogle-sheets-formulagoogle-query-language

Google Sheets Query with mixed data - data starting with a letter not appearing in Query


I originally asked this here but my formula has now adapted and now require assistance again - Google Sheets Query using dependent dropdown

Basically, I have the following Query formula:

=QUERY(Haulage!$A$3:$U," Select * Where A >= date '"&TEXT(Stats!C1, "yyyy-mm-dd")&"' 
and A <= date  '"&TEXT(Stats!C2, "yyyy-mm-dd")&"'"&
IF(Stats!K1="All TOCs",," and lower(K) = '"&LOWER(Stats!K1)&"'")&
IF(Stats!K2="All Classes",," and (Q) = "&Stats!K2*1),)

The formula is basically to enable me to filter between a start and end date. Within the Haulage sheet is a column (C) which is primarily just numeric data but some have a letter followed by numbers. The ones with the letter at the start are not appearing in the above formula in my query. I believe to_text is a solution but struggling to get it to fit into the formula

UPDATE:

Amended formula to:

=QUERY(arrayformula(to_text(Haulage!$A$3:$U))," Select * Where Col1 >= date '"&TEXT(Stats!C1, "yyyy-mm-dd")&"' 
and Col1 <= date  '"&TEXT(Stats!C2, "yyyy-mm-dd")&"'"&
IF(Stats!K1="All TOCs",," and lower(Col11) = '"&LOWER(Stats!K1)&"'")&
IF(Stats!K2="All Classes",," and (Col17) = "&Stats!K2*1),)

Now getting the "Query completed with an empty output" error message


Solution

  • try:

    =ARRAYFORMULA(QUERY({Haulage!A3:A, TO_TEXT(Haulage!B3:U)},
     "where Col1 >= date '"&TEXT(Stats!C1, "yyyy-mm-dd")&"' 
        and Col1 <= date '"&TEXT(Stats!C2, "yyyy-mm-dd")&"'"&
     IF(Stats!K1="All TOCs",,   " and lower(Col11) = '"&LOWER(Stats!K1)&"'")&
     IF(Stats!K2="All Classes",," and (Col17) = '"&Stats!K2&""&"'"), ))
    

    enter image description here