Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Asigning Parent Nodes on Load

Hello,

I was wondering if there is a way to asign parent nodes in the loading script if you know the loading order.

For example,

My data is organized in rows, that have the same field names and everything.

The only thing that diffirenciates them is a level column, 5 to 0.

The hiest hierarchy are 5.

The thing is, the parent of each row is the next value that has a hier hierarchy lvl.

For example:

IDParentIDNameLevel
13Row10
23Row20
310Row34
46Row40
56Row50
67Row61
78Row72
89Row83
910Row94
100Row105

In here you can see that each node has the parentid of the next node with higher hierarchy.

I try using variables that would change their value but you cant do that on the load script.

So i was wondering if there is a way to do this with a function i dont know about or a trick some of you expierienced guys might know.

Any help is appriciated.

Thanks,

KR

P.S. Sry for my poor english

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Maybe like this (assuming a max level of 5 as you stated above):

RAW:

LOAD ID,

     ParentID as Check,

     Name,

     Level

FROM

[https://community.qlik.com/thread/172577]

(html, codepage is 1252, embedded labels, table is @1);

T1:

LOAD *,

  if(Level = 1, ID, Peek(Next1)) as Next1,

  if(Level = 2, ID, Peek(Next2)) as Next2,

  if(Level = 3, ID, Peek(Next3)) as Next3,

  if(Level = 4, ID, Peek(Next4)) as Next4,

  if(Level = 5, ID, Peek(Next5)) as Next5

RESIDENT RAW

ORDER BY ID desc;

DROP TABLE RAW;

RESULT:

LOAD recno() as Recno,

  ID,

  Name,

  Level,

  rangesum(rangemin(if(Level<1,Next1),if(Level <2,Next2),if(Level<3,Next3),if(Level<4,Next4),if(Level<5,Next5))) as ParentID,

  Next1,Next2,Next3,Next4,Next5,

  Check

RESIDENT T1

ORDER BY ID asc  ; 

DROP TABLE T1;

View solution in original post

7 Replies
ramoncova06
Partner - Specialist III
Partner - Specialist III

you can use the hierarchy function for this

swuehl
MVP
MVP

Maybe like this (assuming a max level of 5 as you stated above):

RAW:

LOAD ID,

     ParentID as Check,

     Name,

     Level

FROM

[https://community.qlik.com/thread/172577]

(html, codepage is 1252, embedded labels, table is @1);

T1:

LOAD *,

  if(Level = 1, ID, Peek(Next1)) as Next1,

  if(Level = 2, ID, Peek(Next2)) as Next2,

  if(Level = 3, ID, Peek(Next3)) as Next3,

  if(Level = 4, ID, Peek(Next4)) as Next4,

  if(Level = 5, ID, Peek(Next5)) as Next5

RESIDENT RAW

ORDER BY ID desc;

DROP TABLE RAW;

RESULT:

LOAD recno() as Recno,

  ID,

  Name,

  Level,

  rangesum(rangemin(if(Level<1,Next1),if(Level <2,Next2),if(Level<3,Next3),if(Level<4,Next4),if(Level<5,Next5))) as ParentID,

  Next1,Next2,Next3,Next4,Next5,

  Check

RESIDENT T1

ORDER BY ID asc  ; 

DROP TABLE T1;

vikasmahajan

You can use hirarchy like following example

Test:

HIERARCHY(CHILD_ID, PARENT_ID, [HQ], [Parent Name], [HQ], [Path Name], '/')

LOAD Hqid AS [HQ Code],

     Hqname AS [HQ],

     GeoLevelName AS [Level Name],

     CHILD_ID,

     PARENT_ID

FROM

[..\Qvds\DIM_GeoHQMaster.qvd]

(qvd);

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try using the Hierarchy concepts in Qlikview, check below link hope it helps you.

Hierarchies

Regards,

jagan.

Not applicable
Author

I think i didnt explianed myself apprpiate, the column of parentID is the colum i need to create on the load.

swuehl
MVP
MVP

I think i didnt explianed myself apprpiate, the column of parentID is the colum i need to create on the load.

That's what I assumed. In my example above, I only loaded the existing column as Check to validate the results. I calculate ParentID only using ID and Level.

Not applicable
Author

Thanks alot, this solved my problem completly, ur a qv wizard.

thanks again!