My formula still does exactly the same job, but the LET function makes its logic clear.