Would something like this work?
avgs = Associative Array( dt:ID );
ids = avgs << get keys;
For( i = 1, i <= N Items(ids), i++,
these = As List( dt << get rows where( dt:ID == ids[i] ) );
If( N Items(these) < 5,
n = N Items(these),
n = 5;
Remove From( these, 1, N Items(these) - n );
);
these = Matrix( these );
avgs[ids[i]] = Sum(dt:Value[these]) / n;
);
Show(avgs);