in reply to sort based upon the partial data

Just to clear up a potential misunderstanding, we don't write code here for you.

You can help us to help you better if you show what code you already have, example data, and if you describe how it fails to do what you want, and what you've tried already to fix this.