Aggregation Query Builder doesn't count

Hi, We have reviewed in detail and we found that the problem is presented wi=
th aggregation query that use the attribute of patient that we have created.=
=20
The postgres console print the next error.
=20
ERROR: syntax error at or near ")" at character 617
STATEMENT: SELECT '0' as dataelementid, '0' as categoryoptioncomboid, ou.org=
anisationunitid as sourceid, '0' as periodid,'DHIS-SYSTEM' as comment, '2013=
08' as periodIsoDate,'dataelementname' as dataelementname, 'optioncomboid' a=
s categoryoptioncomboname, ou.name as organisationunitname, count (psi.progr=
aminstanceid ) as value FROM programstageinstance as psi INNER JOIN organisa=
tionunit ou on ou.organisationunitid=3Dpsi.organisationunitid WHERE EXISTS (=
SELECT * FROM patientattributevalue _pav WHERE _pav.patientid =3D pi.patien=
tid and _pav.patientattributeid=3D280 AND p.organisationunitid in (0) AND _p=
av.value )=3D'Especial' ) GROUP BY ou.organisationunitid, ou.name

the error is generated when we edit the aggregation query, but it is don't g=
enerated with aggregation query that use the attibutes of patient that it is=
by default. (Sex).

Thanks,=20

ING. Helder Yesid Castrillon.
Secretar=C3=ADa departamental de salud