I don't think that this
is valid syntax, it seems you're missing the expression to aggregate in your sum() function.
Then, just using set expression
is just clearing any selections in Latest_record_indicator field, it is not filtering your data for latest records (or have I misunderstood what you are trying to show here?).
Finally, I think you need an aggregation function around the aggr() function, to aggregate the table returned from the aggr() function (there are special cases where you don't explicitely need one, but in most cases, you do).
Could you post a small sample app here?