My formula still does exactly the same job, but the LET function makes its logic clear.
Excel's familiar grid can become almost anything when you add a little creativity.