Thanks AiiGW,

I have attached a file to make things easier to understand.

I will look at the aggregate function in the mean time.