Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
emteam162
Creator
Creator

hieararchy

Hi All,

I have a data set as shown below.

I want to make a tree structure by using Hierarchy  function in QV

Niv1Niv0Name
10NAME0
1N1NAME1
1N112NAME2
20NAME02
2B1NAME12
2B112NAME22

The final resultat :

NAME0

     NAME1

          NAME2

Please help me.

Many thanks

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Maybe use something like

INPUT:

LOAD *, RecNO() as NodeID, If(Niv0=0,NULL(), Peek(NodeID)) as ParentID

INLINE [

Niv1, Niv0, Name

1, 0, NAME0

1N, 1, NAME1

1N11, 2, NAME2

2, 0, NAME02

2B, 1, NAME12

2B11, 2, NAME22

];

Hierarchy(NodeID, ParentID, Name,ParentName,Name, Path)

LOAD NodeID, ParentID, Name

Resident INPUT;

DROP TABLE INPUT;

Then create a listbox with option treeview enabled for field Path:

2016-05-17 23_26_20-QlikView x64 - [C__Users_Stefan_Downloads_QlikCommunity_Thread_217262.qvw_].png

View solution in original post

7 Replies
swuehl
MVP
MVP

Your Niv1 and Niv0 fields are not describing parent / child nodes, do they?

Could you describe a bit more detailed the logic / relation of your data?

emteam162
Creator
Creator
Author

Field Values Niv0

0 is the top level

1 is the second level

2 is the last level

santiago_respane
Specialist
Specialist

Hi Said,

Maybe you can start here:

Hierarchy function easy and Efficient with example---

Please let me know if this helps.

Kind regards,

swuehl
MVP
MVP

You always have at most a single parent for a node and a single child?

emteam162
Creator
Creator
Author

I tried that but not working

emteam162
Creator
Creator
Author

yes

swuehl
MVP
MVP

Maybe use something like

INPUT:

LOAD *, RecNO() as NodeID, If(Niv0=0,NULL(), Peek(NodeID)) as ParentID

INLINE [

Niv1, Niv0, Name

1, 0, NAME0

1N, 1, NAME1

1N11, 2, NAME2

2, 0, NAME02

2B, 1, NAME12

2B11, 2, NAME22

];

Hierarchy(NodeID, ParentID, Name,ParentName,Name, Path)

LOAD NodeID, ParentID, Name

Resident INPUT;

DROP TABLE INPUT;

Then create a listbox with option treeview enabled for field Path:

2016-05-17 23_26_20-QlikView x64 - [C__Users_Stefan_Downloads_QlikCommunity_Thread_217262.qvw_].png