Return to previous state in nested Dynamic Panel

Hi there, I have Dynamic Panel A with 4 states, and inside Panel A I have a nested Dynamic Panel B with 2 states.

Once (Panel A:State 1) switches to (PanelA:State 4), I would like to be able to set an action which takes me back to (Panel A:State 1) and shows (Panel B:State 1 or 2) depending what the previous state of Panel B was.

On click I set (Panel A to State 1), and tried to set (Panel B to Previous State) but it doesn’t work.

Do I have to use variables for this?

Many thanks.