You can make a recursive BOM indenter as mentioned, however, with your current set up the only thing you need to do to make it union is to add several UnionAlls which have the subqueries inside of them. As shown below. I use this method because RecursiveCTE indenters don’t like group by functions in the anchor, and I don’t want duplicates of a part within a level.
The union all basically rolls up whatever fields from what is inside it’s subquery into the subquery. In my instance I roll up all the levels, into Level5 subquery, and then put that subquery into my mainquery. Looks ugly, but it works nice for my application
