Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
did
Employee
Employee

Reverse hierarchy: how to convert a horizontal hierarchy to an adjacency list?

Hi everyone,

I was wondering how to reverse a hierarchy?

with other words: how to convert a horizontal hierarchy to an adjacency list model (NodeID, ParentID, Name)?

did_0-1648624235519.png

 

 

 

Many thanks for your ideas

Labels (1)
1 Solution

Accepted Solutions
MarcoWedel

Doesn't create the NodeIDs quite in the same order, but the relations should be correct:

MarcoWedel_0-1648670914756.png

 

table1:
CrossTable (ColNam,Name)
Load RecNo() as ID, *
Inline [
Field1, Field2, Field3
A,BB,DDD
A,CC,EEE
A,CC,FFF
A,BB,DDD
];

table2:
Load AutoNumber(Name) as NodeID,
     If(ID=Previous(ID),AutoNumber(Previous(Name))) as ParentID,
     Name
Resident table1;

Drop Table table1;

 

hope this helps

Marco

View solution in original post

4 Replies
MarcoWedel

please provide an example having consistent values between input and output tables to clarify your requirement.

thanks

did
Employee
Employee
Author

Hi Marco, you're right - I didn't see, that the the second table was wrong. I've just put the right one.

MarcoWedel

Doesn't create the NodeIDs quite in the same order, but the relations should be correct:

MarcoWedel_0-1648670914756.png

 

table1:
CrossTable (ColNam,Name)
Load RecNo() as ID, *
Inline [
Field1, Field2, Field3
A,BB,DDD
A,CC,EEE
A,CC,FFF
A,BB,DDD
];

table2:
Load AutoNumber(Name) as NodeID,
     If(ID=Previous(ID),AutoNumber(Previous(Name))) as ParentID,
     Name
Resident table1;

Drop Table table1;

 

hope this helps

Marco

did
Employee
Employee
Author

It works!! Many thanks, Marco!