title: Aggregate functions in Sparql query with empty records
body: <p>I've been trying to run a sparql query against <a href="https://landregistry.data.gov.uk/app/qonsole#" rel="nofollow noreferrer">https://landregistry.data.gov.uk/app/qonsole#</a> to yield some sold properties result.</p>
  <p>The query is the following:</p>
  <pre><code>  PREFIX  xsd:  &lt;http://www.w3.org/2001/XMLSchema#&gt;
    PREFIX  ukhpi: &lt;http://landregistry.data.gov.uk/def/ukhpi/&gt;
  
    SELECT  sum(?ukhpi_salesVolume)
    WHERE
       { { SELECT  ?ukhpi_refMonth ?item
           WHERE
            { ?item  ukhpi:refRegion  &lt;http://landregistry.data.gov.uk/id/region/haringey&gt; ;
                 ukhpi:refMonth   ?ukhpi_refMonth
               FILTER ( ?ukhpi_refMonth &gt;= &quot;2019-03&quot;^^xsd:gYearMonth )
               FILTER ( ?ukhpi_refMonth &lt; &quot;2020-03&quot;^^xsd:gYearMonth )
             
            }
        }
        OPTIONAL
      { ?item  ukhpi:salesVolume  ?ukhpi_salesVolume }
    }
  </code></pre>
  <p>The problem is, the result from this is empty. However, if i run the same query without the SUM on the 4th line, i can see there are 11 integer records.</p>
  <p>My thoughts are that there is a 12th, empty record which causes all the issues in the SUM operation, but sparql is not my storngest side so i'm not sure how to filter this (and remove any empty records) if that's really the problem.</p>
  <p>I've also noticed that most of the aggregate functions do not work as well(min, max, avg). *Count does, and returns 11</p>