How to expand parent-child in Power Query/M

Hi everyone,

I have got an interesting case where I need to start from the child and find its parents. Futher, I need to check that parent and see if that has another parent. So, it would be a recursive calculation. Below snapshot show the source/required result and my current result. I do not know how to fix the problem.

Can anyone please check that? I have attached the sample pbix for this.

Recursive Code.pbix (26.0 KB)