That this expression-part here works showed that the applied date-logic itself and the syntax is generally correct and should be therefore also work within the whole expression. It's difficult to guess why not.
To exclude that yet any formatting-stuff caused it try the following variants (not all together - unless properly commented):
If your other expression-steps from above work it should also work combined. At the moment I don't see an obvious issue. In similar cases I would reduce all possible complexity and looking if it returned the expected values and then adding step by step more conditions/variables/expression-parts to find the point where it breaks respectively it returned unexpected results. In your case you may start with something like this: