You have the rotation down, but the only way to get the window sitting right on the table when it’s ‘vertical’ is to also shift the location.
You need to shift it up ( I don’t know the orientation of you axis ) when you have it vertical. So add enough to move it up, and then subtract enough to move it down again, when longways.
Use AddLocalOffset to the axis pointing up the table.