Never realised about the NOTSORTED option before and it works like magic! Learnt something new today! It looks like it is now working and it seem to work too even I add more level into the by group. I will probably need to generate more records and find some really tricky examples which switch around at all time to test if it works perfectly. Nevertheless, thanks very much for your suggestion!
... View more