Search code examples
google-apps-scriptgoogle-sheetsgoogle-query-language

Google sheets query duplicate 1st line + results bug


I create a google form bounded trough a function to a google form an I created a 2° tab to filter the results with a QUERY You can see the result here

https://docs.google.com/spreadsheets/d/1nseIV5ieqsifOKwWvx7crbcTxxMZ3RKpb1kNUsoMt44/edit?usp=sharing

In the "Ricerca" tab you can filter the line in the "Risultati" tab. You can see the QUERY

=QUERY(Revisioni!A3:AI; "select * where (F contains '"&F2&"') and (E contains '"&H2&"') and
((Month(N)+1 = "&B2&" and year(N) = "&D2&" and O=false) or 
(Month(P)+1 = "&B2&" and year(P) = "&D2&" and Q=false) or 
(Month(R)+1 = "&B2&" and year(R) = "&D2&" and S=false) or 
(Month(T)+1 = "&B2&" and year(T) = "&D2&" and U=false) or 
(Month(V)+1 = "&B2&" and year(V) = "&D2&" and W=false) or 
(Month(X)+1 = "&B2&" and year(X) = "&D2&" and Y=false) or 
(Month(Z)+1 = "&B2&" and year(Z) = "&D2&" and AA=false) or 
(Month(AB)+1 = "&B2&" and year(AB) = "&D2&" and AC=false) or 
(Month(AD)+1 = "&B2&" and year(AD) = "&D2&" and AE=false) or 
(Month(AF)+1 = "&B2&" and year(AF) = "&D2&" and AG=false))")

in the Ricerca!A5 cell.

As you can see the result is something like enter image description here

it merges the 1° row + the 1° resut row enter image description here

How can I have correct results?


Solution

  • Explanation:

    You should add a 0 as the last argument of QUERY.

    According to the documentation:

    headers - [ OPTIONAL ] - The number of header rows at the top of data. If omitted or set to -1, the value is guessed based on the content of data.

    Therefore, it makes the assumption that the third row in the source data (A3) is a header and this is why it adds it to the output of the QUERY.


    Solution:

    =QUERY(Revisioni!A3:AI; "select * where (F contains '"&F2&"') and (E contains '"&H2&"') and
    ((Month(N)+1 = "&B2&" and year(N) = "&D2&" and O=false) or 
    (Month(P)+1 = "&B2&" and year(P) = "&D2&" and Q=false) or 
    (Month(R)+1 = "&B2&" and year(R) = "&D2&" and S=false) or 
    (Month(T)+1 = "&B2&" and year(T) = "&D2&" and U=false) or 
    (Month(V)+1 = "&B2&" and year(V) = "&D2&" and W=false) or 
    (Month(X)+1 = "&B2&" and year(X) = "&D2&" and Y=false) or 
    (Month(Z)+1 = "&B2&" and year(Z) = "&D2&" and AA=false) or 
    (Month(AB)+1 = "&B2&" and year(AB) = "&D2&" and AC=false) or 
    (Month(AD)+1 = "&B2&" and year(AD) = "&D2&" and AE=false) or 
    (Month(AF)+1 = "&B2&" and year(AF) = "&D2&" and AG=false))";0)
    

    References: