Parent/Child Formula for Levels

I am trying to create a parent child formula to deliver numbered levels. The formula I have so far is working for a couple of levels but not 4-5 levels deep (see example). I've worked on this and have now confused myself so needing a bit of helping getting out of my own 'circular reference'

=IF(OR(COUNT(ANCESTORS(Task@row)) = 0, COUNT(CHILDREN(Task@row)) > 0), 1, IF(COUNT(ANCESTORS(Task@row)) > 0, 2))


Help Article Resources

Want to practice working with formulas directly in Smartsheet?

Check out the Formula Handbook template!