En casos como esos, you personalmente lo que hago de la siguente manera. Creo un procedure file. ejemplo: mylibrary.prg
En MyLibrary.prg tendrias PROCEDURES y FUNCTIONS:
**********************************
FUNCTION SumaMensual( m.lcDBF, m.lnMonth )
**********************************
LOCAL m.lcSQLWhere, m.lnReturnValue
m.lnReturnValue = 0
m.lcSQLWhere = "MONTH(tabledate) = " + TRANS( m.lnMonth )
SELECT ;
SUM(IIF(cond,option1,option2)) AS n_amount ;
FROM m.lcDBF ;
WHERE &lcSQLWhere.
INTO ARRAY aResults
IF _TALLY > 0
m.lnReturnValue = aResults[1]
ENDIF
RETURN( m.lnReturnValue )
En el reporte. La expression seria for ejemplo:
SumaMensual( "c:\mytable.dbf", 12 ) && pasa la tabla y el mes
Al llamar to reporte, lo haces asi:
SET PROCEDURE TO MyLibrary
REPORT xyz TO PRINT NOCONSOLE
SET PROCEDURE TO
Dejame saber si esto no te es muy claro.