I have a solution that works fine in Excel spreadsheet, but encounters circular reference error in both Power Query M and BI DAX. Need help please.

Let's say I have 2 columns:

Column A - Employee ID
Column B - Manager ID

I'm trying to create a 3rd column [Hierarchy] level with the CEO defined as 0 and each level below him +1.

In an Excel table, this works for me:
= IF ( [Employee ID] = (CEO's ID), 0,
IF ( INDEX( [Hierarchy], MATCH( @[Manager ID], [Employee ID], 0)) +1 )

However if I try to replicate this in Power Query or DAX measures it returns with circular reference error.

I searched the forums for circular reference solutions. There was a solution to create 2 index columns, one starting with 0 and another starting with 1 then merge and calculate. However this only satisfies one pass, and is a non iterative solution. It won't work unless we know exactly how many hierarchy levels, and even then need to duplicate the series of steps for each pass, which seems very cumbersome.

Any genius able to help please?