Convert data input level (level 1, 2, 3) into tree (1, 1.1, 1.1.1, 1.1.2...)

Hello KNIME community,

I have a list of data input, where every line is assigned a level. If the value of the level increases, that means the data is associated one level down in a tree position.

The order of the data is extremely important, as it defines which e.g. level 5 item, belongs to which level 4 top level entry. As this is extremly volatil and can not be handled in a good way doing data operations, I want to convert this information into an unambigous tree value.

So I start with giving every level 1 line its own number (1, 2, 3…), then for every level 2 line the corresbonding level 1 value, plus its own level 2 value (1.1, 1.2… 2.1, 2.2…).

While the values only go one step at a time into higher levels (so if line 10 is level 4, line 11 can only increase to level 5, not to level 6 or higher), if the level decreases it can skip multiple levels (so if line 14 is level 6, line 15 can also be level 4). At the moment the levels go from 1 to 17, but this could change in the future, so best case would be, it is not dependent on a hard copy value of the number of available levels.

There are a view ideas, that this should be possible with a for loop, but I am not getting there. Could you help me, please?

To make it 100% clear, I defined a table of example data - “Line” and “Level” as input - together with “Treeposition” as the desired Output.

| Line (Input) | Level (Input) | Treeposition (Output) |
| 1            | 1             | 1                     |
| 2            | 2             | 1.1                   |
| 3            | 3             | 1.1.1                 |
| 4            | 3             | 1.1.2                 |
| 5            | 4             | 1.1.2.1               |
| 6            | 3             | 1.1.3                 |
| 7            | 3             | 1.1.4                 |
| 8            | 2             | 1.2                   |
| 9            | 3             | 1.2.1                 |
| 10           | 4             | 1.2.1.1               |
| 11           | 5             | 1.2.1.1.1             |
| 12           | 5             | 1.2.1.1.2             |
| 13           | 5             | 1.2.1.1.3             |
| 14           | 6             | 1.2.1.1.3.1           |
| 15           | 4             | 1.2.1.2               |
| 16           | 2             | 1.3                   |
| 17           | 2             | 1.4                   |
| 18           | 3             | 1.4.1                 |
| 19           | 4             | 1.4.1.1               |
| 20           | 1             | 2                     |
| 21           | 2             | 2.1                   |
| 22           | 3             | 2.1.1                 |

Thank you very much in advance.

Christoph