It might be possible to work around this with jinja, but I am reminded of the words of the guru... "Ansible is not a programming language"...
Can I suggest instead...
Some task that registers variable X
Another task that registers variable a but is only run when X is true
A third task that registers variable a but is only run when X is false
A fourth task that uses variable a
Unless you need both y and z at the same time then this satisfies your use case and simplifies your actual playbook...
Of course even this might not be needed depending on what you are actually trying to do.
I hope that this helps,
Adam