Power Query identify parent records in hierarchical nested loops
<p>The data is a series of nested hierarchies.  Within the loops are child records. The data is a list of components and sub components. The subcomponents may have subcomponents themselves.</p>

<p>The top of the loops are parent records to these nested child records. These loops can be nested within each other.</p>

<p>The data set is ordered so the records in proper order.</p>

<p>Below is screenshot of how it appears as an indented hierarchical text file.</p>

<p>Basically need to identify the top level of of each loop so I can get other column information from them to compare to nested child values. Nested child properties should be same as parent. I need to check this is the case.</p>

<p>I have no code to show. Not sure how to proceed. Group By seems promising, but need to figure out way to recurse back up hierarchy to the top of current loop, and relate that to each of its child records, so I can compare their properties.</p>

<p><a href="https://i.stack.imgur.com/9nxsO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9nxsO.jpg" alt="enter image description here"></a></p>

<p>Sample data, first column Index is simply line number, and second column Level Number is the hierarchy level. </p>

<p>There is unique combination of line number and hierarchy level that would identify each level's parent "Index-Level". I would like to associate this Parent Index-Level with each of its child levels.</p>

<p>The data is text format but is brought into Power Query where the analysis has to happen.</p>

<pre><code>Index   Level Number  Parent Index-Level
1   1
2   2
3   3
4   4
5   5
6   6
7   7
8   8
9   9
10  10
11  11
12  12
13  13
14  14
15  14
16  14
17  14
18  14
19  14
20  14
21  13
22  13
23  13
24  14
25  14
26  14
27  11
28  9
29  9
30  9
31  9
32  9
33  9
34  9
35  8
36  9
37  10
38  11
39  11
40  12
41  12
42  13
43  13
44  13
45  11
46  12
47  13
48  14
49  14
50  14
</code></pre>