I have the following (simplified from original) formula which pulls in data from another sheet (multiple sheets in the original formula) and calculates the sum of a column based on the month() value of another column:
=QUERY({
IFERROR(IMPORTRANGE('C1'!$B$5, "PLACEMENTS!A4:L1000"), {"",TO_DATE(0),"","","","","","","","","",""})},
"SELECT SUM(Col8) WHERE Col2 IS NOT NULL AND month(Col2)+1="& MONTH($A3) &" AND Col1="""&B$2&""""& IF(NOT($C$1="ALL"), "AND Col6="""&$C$1&"""" ,)& " label SUM(Col8) ''",0)
I keep getting the #VALUE! Error:
Unable to parse query string for Function QUERY parameter 2: Can't perform the function month on a column that is not a Date or a DateTime column
If I remove the IFERROR
wrapper to the IMPORTRANGE
statement then the error goes away and as you can see, in the case of an error on the IMPORTRANGE
statement, an empty array with Col2 set as a date with TO_DATE(0)
is inserted.
This formula without the IFERROR
works fine, and pulls in rows and provides a SUM
value:
=QUERY({IMPORTRANGE('C1'!$B$5, "PLACEMENTS!A4:L1000")},"SELECT SUM(Col8) WHERE Col2 IS NOT NULL AND month(Col2)+1="& MONTH($A3) &" AND Col1="""&B$2&""""& IF(NOT($C$1="ALL"), "AND Col6="""&$C$1&"""" ,)& " label SUM(Col8) ''",0)
Here's a link to a sample sheet that the formula imports from with the same structure of data: Sample Sheet Data
If the Query
works without the IFERROR
wrapper, why does it produce the error about Col2 with the IFERROR
wrapper in place which shouldn't be triggered in this case? This exact same formula works fine on another user's spreadsheet. Is this a Google Sheets/Query bug or is there something I'm doing wrong here? Thanks