This is the list of which material goes into what semi finished good/finished good that I start with:

And I would like to turn it into this structure:

Any suggestions on how to get the data into this format?
I've tried joining the data with itself and then that output with the original data, but all I get is the first two product hierarchies. Is this the best way to go about this? I'm pretty new to Alteryx so I don't know all the in's and out's yet.