Can an if then column contain reference to a relation?

Ultimately I am trying to display the topmost value in a relationship and use it to identify a group
The scenario is for a pyramid structure organization

The top most level has 2 branch managers = Adam and Eve with multiple levels or branches each- any new hires no matter how far down the line ultimately fall under 1 of 2 main branches -
I have parent child relationships set up which work from the top down

As members join the organization they only know their immediate supervisor or “sponsor” so in an automated system I want the system to work in reverse and have the topmost level name returned when people onboards themselves.

So Adam (branch manager 1) hires Ann who hires Mark who hires Mary who hires Jack. When Jack onboards himself and lists Mary as his sponsor I want Adam to appear as the ultimate manager for Jack.

Trying to keep it all automated