PREFIX : PREFIX xsd: SELECT ?X (SAMPLE(?v) AS ?S) { ?s :p ?v . OPTIONAL { ?s :q ?w } } GROUP BY (COALESCE(?w, "1605-11-05"^^xsd:date) AS ?X)