Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to create hierarchy levels in qlikview

Hi All,

Please any help in creating hierarchy levels in qlikview will be appreciated:

Below is code in oracle, where LEVEL field is created, which I want to implement in qlikview:

SELECT employee_id, last_name, manager_id, LEVEL

   FROM employees

START WITH manager_id in ('100')

   CONNECT BY PRIOR employee_id = manager_id;

EMPLOYEE_ID LAST_NAME      MANAGER_ID      LEVEL

----------- ------------------------- ---------- ----------

        101 Jane                                 100          1

        108 Greenberg                        101          2

        109 Faviet                               108          3

        110 Chen                                108          3

        111 Sciarra                             108          3

        112 Urman                              108          3

        113 Popp                                 108          3

Thanks in advance:)

Regards

Neetha

1 Solution

Accepted Solutions
luciancotea
Specialist
Specialist

Table1:

Hierarchy(employee_id, manager_id, last_name)

SELECT employee_id, last_name, manager_id, LEVEL

   FROM employees

START WITH manager_id in ('100')

   CONNECT BY PRIOR employee_id = manager_id;

View solution in original post

16 Replies
MayilVahanan

Hi

You can use same Oracle query in Qlikview and create it.

Otherwise, Please refer

Hierarchy and Hierarchy Belongs to

Hierarchies

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Anonymous
Not applicable
Author

This blog post by Henric and it's links are well worth a read :

     Hierarchies

awhitfield
Partner - Champion
Partner - Champion

Hi Neetha

There is an example in the QV Help file

Hierarchy

The hierarchy prefix is used to transform a parent-child hierarchy table to a table that is useful in a QlikView data model. It can be put in front of a LOAD or a SELECT statement and will use the result of the loading statement as input for a table transformation.

The prefix creates an expanded nodes table, which normally has the same number of records as the input table, but in addition each level in the hierarchy is stored in a separate field. The path field can be used in a tree structure.

Syntax:

Hierarchy ( NodeID, ParentID, NodeName, [ParentName], [PathSource], [PathName], [PathDelimiter], [Depth] ) (loadstatement | selectstatement)

The input table must be an adjacent nodes table. Adjacent nodes tables are tables where each record corresponds to a node and has a field that contains a reference to the parent node. In such a table the node is stored on one record only but the node can still have any number of children. The table may of course contain additional fields describing attributes for the nodes.

Usually the input table has exactly one record per node and in such a case the output table will contain the same number of records. However, sometimes there are nodes with multiple parents, i.e. one node is represented by several records in the input table. If so, the output table may have more records than the input table.

All nodes with a parent id not found in the node id column (including nodes with missing parent id) will be considered as roots. Also, only nodes with a connection to a root node - direct or indirect - will be loaded, thus avoiding circular references.

Additional fields containing the name of the parent node, the path of the node and the depth of the node can be created.

Arguments:

ArgumentDescription
NodeIDThe name of the field that contains the node id. This field must exist in the input table.
ParentIDThe name of the field that contains the node id of the parent node. This field must exist in the input table.
NodeNameThe name of the field that contains the name of the node. This field must exist in the input table.
ParentNameA string used to name the new ParentName field. If omitted, this field will not be created.
ParentSourceThe name of the field that contains the name of the node used to build the node path. Optional parameter. If omitted, NodeName will be used.
PathNameA string used to name the new Path field, which contains the path from the root to the node. Optional parameter. If omitted, this field will not be created.
PathDelimiterA string used as delimiter in the new Path field. Optional parameter. If omitted, ‘/’ will be used.
DepthA string used to name the new Depth field, which contains the depth of the node in the hierarchy. Optional parameter. If omitted, this field will not be created.

Example:

Hierarchy(NodeID, ParentID, NodeName, ParentName, NodeName, PathName, '\', Depth) LOAD * inline [

NodeID, ParentID, NodeName

1, 4, London

2, 3, Munich

3, 5, Germany

4, 5, UK

5, , Europe

];

Result:

NodeIDNodeNameParentIDParentNameNodeName1NodeName2NodeName3PathNameDepth
5Europe -Europe--Europe1
3Germany5EuropeEuropeGermany-Europe\Germany2
2Munich3GermanyEuropeGermanyMunichEurope\Germany\Munich3
4UK5EuropeEuropeUK-Europe\UK2
1London4UKEuropeUKLondonEurope\UK\London
luciancotea
Specialist
Specialist

Table1:

Hierarchy(employee_id, manager_id, last_name)

SELECT employee_id, last_name, manager_id, LEVEL

   FROM employees

START WITH manager_id in ('100')

   CONNECT BY PRIOR employee_id = manager_id;

Anonymous
Not applicable
Author

Hi Mayil,

Able to create Level using SQL query in qlikview, but when using preceding load on the sql statement, it gives error Level field not found.

Regards

Neetha

Anonymous
Not applicable
Author

Hi Lucian,

Do we need to add anything before Hierarchy(employee_id, manager_id, last_name) statement please?

Regards

Neetha

luciancotea
Specialist
Specialist

No. Assuming that your SQL statement works, this is what you should have in the QlikView script.

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Neetha,

You dont need to create any Level in SQL. QlikView will automatically do that.

Find the example attached with this.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Anonymous
Not applicable
Author

Hi Lucian,

I am getting error OLEDB read failed.