Hello , I found what was the problem there with your formulas , and I made simple change in your existing formula.
Please check my file and copy that formula.
Your formula was working absolutely right , but there was issue with formatting ,which I have solved out.
If you want , you can check . and If you satisfy , we can work together in future. If it's correct , I don't need payment .
This is the sheet which I have added.
--> https://docs.google.com/spreadsheets/d/1XRmgxaP65uCbFOSkFFx3_-z4002FoFB7yV-8LhOdKrE/edit#gid=650833108