The solution I tried is messing up my other fields. So, I have kept it open now. I tried your option too. It does work on this sample data but is not constant for all selections in my data model. Let me provide a better example.
Meanwhile please let me know if you can think of any alternative for this scenario.