Search code examples
google-sheets

Google Sheet - QUERY SELECT does not handle apostrophe in WHERE CLAUSE


I have this Google Sheet report.

The problem is when my client name has an apostrophe, it breaks the formula.

=IFERROR(INDEX(QUERY(Projects!$1:$2018, "select sum(G) where A='"&A2&"'"),2), 0)

https://docs.google.com/spreadsheets/d/16UOU5iMwieHjVmV81TdK3_emxyj-wFqXa8u5Nia7Wkg/edit#gid=1016414243

Do you know how I can change this ?

Thanks.


Solution

  • Try with triple double quotes to escape those single quotes you have:

    =IFERROR(INDEX(QUERY(Projects!$1:$2018, "select sum(G) where A="""&A2&""""),2), 0)
    

    enter image description here

    You can also use SUMIF, and don't worry about how the values are written:

    =SUMIF(Projects!A:A,A2,Projects!G:G)
    

    enter image description here