Google Sheets Query if blank

Viewed 400

I have the following query which works fine except if there is not a value in D that matches F2. I get #N/A but not sure how to correct it so it shows "0".

=ABS(QUERY(Transactions,"SELECT SUM(E) WHERE D = '"&$F2&"' AND B > date '"&TEXT($C$1,"yyyy-mm-dd")&"' AND B <= date '"&TEXT($C$2,"yyyy-mm-dd")&"' GROUP BY D LABEL SUM(E) '' ",0))
1 Answers

You can try:

=IFERROR(ABS(QUERY(Transactions,
 "SELECT SUM(E) 
  WHERE D = '"&$F2&"' 
    AND B >  date '"&TEXT($C$1,"yyyy-mm-dd")&"' 
    AND B <= date '"&TEXT($C$2,"yyyy-mm-dd")&"' 
  GROUP BY D 
  LABEL SUM(E) '' ", 0)), 0)

The function used is the IFERROR:

Returns the first argument if it is not an error value, otherwise returns the second argument if present, or a blank if the second argument is absent.

You can check on the use and further explanation of it on the following link:

Related