I tried both WhileReadingRecords, BeforeReadingRecords in front of the code in the "RecentActivity" formula field like this

Code:
WhileReadingRecords;
If {Conthist.ondate} = nthlargest(1,{Conthist.ondate}) then Yes
 else no
The same error again appeared

Error:
This formula cannot be used because it must be evaluated later.

I also tried adding them to the beginning of the record selection code like this

Code:
WhileReadingRecords;
{CONTHIST.SRECTYPE} <> "O" and
{CONTHIST.LOPRECID} = {?Pm-OPMGR.OPID} and
{@RecentActivity} = yes
Again the same error appears. I also tried the WhilePrintingRecords and
EvaluateAfter({@RecentActivity}) but again the same error appears. Any other suggestions??