I would be BS'ing you if I tried to explain that part, I found the formula once and have used it ever since.
What I'm not sure of is why it isn't working for you. I copied your samples into a spreadsheet then applied the formula and it worked fine.
And I see that AlKey's variant on the formula also works.
What isn't working w/mine?