Flow variables through non-active ports

Hi

I am having the inconvenience that when I have flow branches by switches (if/case), and I close them through case end or if end, and there is a flow variable involved that must take different values in the different branches, at the end of the switch it will take the value that I have set in the first port connected to the closure, even if the port is inactive. As shown in the figure.

What can I do? I need to keep the flow variable value from the active port