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

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to create an adjacent nodes table from an expanded nodes file?

I have a file in this format

Level1Level2Level3Level4
1111
1112
1223
1224
1234

and want to convert it to this format

IdParentId
11
21
31
41

anyone know of an easy way to do this?

5 Replies
johnw
Champion III
Champion III

I don't understand your data. Why does the same number appear on multiple levels on the same line?  Why do all IDs have the same parent?

Not applicable
Author

Do you mean you want to do this:

IDParentID
11
11
11
11
11
21
21
22
22
22
31
31
32
32
33
41
42
43
43
44
Not applicable
Author

It's just random data. Ill post an example of the real info.

On Dec 27, 2011, at 7:09 PM, John Witherspoon <

Not applicable
Author

Yes, that's the format I need to end up with.

Sent from my iPad

On Dec 27, 2011, at 7:49 PM, "B.Sarcich" <

Not applicable
Author

You could do something like this:

RAW:
LOAD * INLINE [
Level1, Level2, Level3, Level4
1, 1, 1, 1
1, 1, 1, 2
1, 2, 2, 3
1, 2, 2, 4
1, 2, 3, 4
];

FOR EACH FieldNo IN '1', '2', '3', '4'

LET FieldName = 'Level' & '$(FieldNo)';

ID_LIST:
LOAD
   $(FieldNo) As ID,
   $(FieldName) As ParentID
RESIDENT RAW;

NEXT FieldNo

RAW can be loaded from an excel file or wherever else. I am assuming here that the field names are Level1, Level2 etc. This example is of course not dynamic; you must know how many fields there are and code that into the FOR EACH section. Possibly you can come up with a way to dynamically put that into a variable and put the variable after the IN.

Someone else can probably come up with a smarter way to do this than me anyway.