So there was no issues in the code just issues with the actual data
The issue was with the data the logic is correct