Parent Child Levels with Workflow

I have a table “Parent_Child” with columns (My_Id, My_Parent_Id)

Sample Data

A1, Null
A2, A1
A3, A1
A4, A2
A5, A2
A6, A4
A7, A5

I want a Knime work flow that creates another column “Level”. This should show the Level of the ID
In above Data A1 should be at Level 0, A2 and A3 should be at Level 1, A4 should be at Level 2 and so on.

Can some one help how to achieve this with workflow in Knime?

Try the String Manipulation node to strip the “A” and put the result in your new column.

1 Like

I was on my phone when I replied earlier so I couldn’t post a workflow. This should work. I took your input data literally. Please mark “solved” if it meets your needs. if not, get back to me.
Parent Child Levels.knwf (84.0 KB)

1 Like

could you please send me screenshots as I am unable to download due to security

1 Like

This is just a sample data by the way stripping A won’t help with actual data

1 Like

No one can help you if they don’t have real data or at least dummy data with the correct configuration. We can only work with what you provide.

3 Likes

A1012, Null
BB2001, A1012
BB2233, A1012
C23245, BB2001
CC4567, BB2001
Df6543, C23245
CC45345, CC4567

Try this. You should only need the three nodes inside the red box. I needed the others to prep the data from your post since you didn’t upload a file. The workflow uses regex to extract the last character from the parent column.
Parent Child Levels.knwf (81.2 KB)




1 Like

Sadly, this is the wrong output, row 2 and 3 should be at level 1

Where am i supposed to extract the 1 from in row 2 and why? You need to explain what you want better. You’re making me guess at a moving target.

1 Like

Hi @sudhirkumra,

you can use a Python Node to get the correct Parent / Child relations. Just the other day I created one which should solve you task.

Here’s the workflow I created (@rfeigel I copied the part of the data prep from you workflow):

Andi

Thanks but we only had 7 rows

BB2001 is child of A1012 so it should have been Level 1

1 Like

My result is correct, check again
A1012 is parent of BB2001. Level = 1

1 Like

Where is the workflow please?

There is a link in my post. Just Click on it

1 Like

Unfortunately, I am unable to install Knime on this machine and my work is on other secured machine. Will it be possible for you to send screenshots of workflow. Preferably without Python as we cannot install python or any other extensions on the secured machine