Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
kumar2
Contributor III
Contributor III

Parent and child data model

Hi,

We have requirement where Parent is linked to the Sub Parent or directly child if a parent is linked to the Sub parent then that sub parent will also have the child .Please find the data model screen shot for reference

kumar2_0-1600280795567.png

 

And input for this is kept in the single table using the table we need to divide the data model. Please find the below sample input

CategoryIDNameParent
Parent1High1 
Child2Low13
Parent3Mid11
Child4Low28
Parent5Mid31
Child6Low48
Parent7High2 
Parent8High3 
Child10Low51
Child11Low33

 

and in the input we have category where Sub parent and parent is both categories into parent in order to recognize the parent data in the last column if data for the last column is blank then the Id is parent ID

Category (Parent)--->Last Column data id Blank then it is parent ID

Category(Parent)----> last column  is not Blank it consists of the Parent ID then it is Sub Parent ID

Category(Child)---> Irrespective of anything ID may be available or not if ID is available then the child is linked to the Parent or Sub parent

Note:-Sub Parent much and should have Parent ID

 

Expected Output when the user selects the "High1" he should able to see his Sub Parent i.e., "Mid1" and "Mid3" again "Mid1" is connected to  the Child "Low1" and "Low3" he should also able to see those two as well

and also the child which are directly linked to "High 1" i.e., "Low5"

 

Thanks for your response

 

Thanks,

Chetan

1 Solution

Accepted Solutions
jwjackso
Specialist III
Specialist III

Look at the HierarchyBelongsTo  and Hierarchy  functions.  Using the data below:

Data:
HierarchyBelongsTo(ID,Parent,Name,AncestorID,AncestorName,DepthDiff)
Load * Inline [
Category,ID,Name,Parent
Parent,1,High1,
Child,2,Low1,3
Parent,3,Mid1,1
Child,4,Low2,8
Parent,5,Mid3,1
Child,6,Low4,8
Parent,7,High2,
Parent,8,High3,
Child,10,Low5,1
Child,11,Low3,3
];

Data2:
Hierarchy(ID,ParentID,NodeName)
Load ID,
Parent as ParentID,
Name as NodeName;
Load * Inline [
Category,ID,Name,Parent
Parent,1,High1,
Child,2,Low1,3
Parent,3,Mid1,1
Child,4,Low2,8
Parent,5,Mid3,1
Child,6,Low4,8
Parent,7,High2,
Parent,8,High3,
Child,10,Low5,1
Child,11,Low3,3
];

 

hierarchy.PNG

View solution in original post

3 Replies
jwjackso
Specialist III
Specialist III

Look at the HierarchyBelongsTo  and Hierarchy  functions.  Using the data below:

Data:
HierarchyBelongsTo(ID,Parent,Name,AncestorID,AncestorName,DepthDiff)
Load * Inline [
Category,ID,Name,Parent
Parent,1,High1,
Child,2,Low1,3
Parent,3,Mid1,1
Child,4,Low2,8
Parent,5,Mid3,1
Child,6,Low4,8
Parent,7,High2,
Parent,8,High3,
Child,10,Low5,1
Child,11,Low3,3
];

Data2:
Hierarchy(ID,ParentID,NodeName)
Load ID,
Parent as ParentID,
Name as NodeName;
Load * Inline [
Category,ID,Name,Parent
Parent,1,High1,
Child,2,Low1,3
Parent,3,Mid1,1
Child,4,Low2,8
Parent,5,Mid3,1
Child,6,Low4,8
Parent,7,High2,
Parent,8,High3,
Child,10,Low5,1
Child,11,Low3,3
];

 

hierarchy.PNG

gobravedave
Contributor
Contributor

The good news is that you can do this ver easily using the  network view. However you may want to "like" the feature request to anchor group by colours and the inclusion of a legend.

BigBadBoss
Contributor
Contributor

I dont understand how you can write AncestorID & AncestorName when the columns are not present in the loaded data table? When I try I get error message Field 'AcestorID' not found.