&& parms or condition would be empty or not empty && if you want all person or one person. lcPerson='person code' lcCode='somecode' lcPerson=IIF(!EMPTY(lcPerson),"person="+"'"+lcPerson+"'",'') lcCode=IIF(!EMPTY(lcCode),"code="+"'"+lcCode+"'",'') lcCond=IIF(!EMPTY(lcPerson),' and '+lcPerson,'')+ ; IIF(!EMPTY(lcCode),' and '+lcCode,'') && date conditon lcWhere='where date < somedate '+lcCond && supposed table has index tag of person/code/date && first, querys records within criteria.. && and orders them by person/code/date.. lcSource=SYS(2015) select * from (mycursor) ; &lcWhere ; group by person,code into (lcSource) NOFILTER order by person,code,date && collect max.date's record per person/code && 'group by' automatically takes last record. lcTarget=SYS(2015) select person,date,code,value ; from (lcTarget) ; group by person,code into (lcTarget) order by person,code && Hacker's Guide says..this kind of query is not reliable.. && I've tried many times in similar situation like you but && didn't find a problem by now. && But I don't take this method for not-large data, would rather && use 'set key to' after proper indexing. && Someone's advice would be appreciated.Just my Thoughts.