Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
BI & Data Trends 2021. Discover the top 10 trends emerging in today. Join us on Dec. 8th REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Not applicable

Separate strings from field with slash

Hi everybody,

I'm trying to make a hierarchy tree. I've got a field that contains the complete relation between fathers and sons and each node ID is separated from another by the use of a "/" in this way

/parentID/childID/grandsonID/sonofthegrandsonID/

and every parent can have a different number of children (some parents have 2 children, some have 3, some have 4 and some have 5 children).

How can I create more fields from the one that I have in order to get a number of fields equal to the numer of chidlren?

So, in my case I would like to have 5 different fields, one for each child.

Thanks a lot for your help and for your attention

Best regards

Nicolò Cogno

1 Solution

Accepted Solutions
Highlighted

Then force one...

SubField(FieldName & '/', '/', 6) as Son4,

SubField(FieldName & '/', '/', 5) as Son3,

SubField(FieldName & '/', '/', 4) as Son2,

SubField(FieldName & '/', '/', 3) as Son1,

SubField(FieldName & '/', '/', 2) as Father

View solution in original post

7 Replies
Highlighted

May be like this:

SubField(FieldName, '/', 1) as FielName1,

SubField(FieldName, '/', 2) as FielName2,

SubField(FieldName, '/', 3) as FielName3,

SubField(FieldName, '/', 4) as FielName4,

SubField(FieldName, '/', 5) as FielName5,

Highlighted
Not applicable

This works! Thanks a lot for your help

Highlighted
Not applicable

I'm sorry, but there's a little thing that is not working yet

My paths are written in this way

/parentID/childID/grandsonID/sonofthegrandsonID



and so I'm using

SubField(FieldName, '/', -1) as Son4,

SubField(FieldName, '/', -2) as Son3,

SubField(FieldName, '/', -3) as Son2,

SubField(FieldName, '/', -4) as Son1,

SubField(FieldName, '/', -5) as Father.



The problem is that in this way the paths with less than 5 elements are giving their elements to the fith field, than to the fourth field ecc and the fields that are at the beginning are left blank

How can I solve this? Should I do something like a conditional loading that takes into account the number of '/' that it finds in the string?

Thanks a lot again!!!!

Highlighted

How about if you do this

SubField(FieldName, '/', 6) as Son4,

SubField(FieldName, '/', 5) as Son3,

SubField(FieldName, '/', 4) as Son2,

SubField(FieldName, '/', 3) as Son1,

SubField(FieldName, '/', 2) as Father

Highlighted
Not applicable

I thought about it, but I don't have a '/' at the end of the path

Highlighted

Then force one...

SubField(FieldName & '/', '/', 6) as Son4,

SubField(FieldName & '/', '/', 5) as Son3,

SubField(FieldName & '/', '/', 4) as Son2,

SubField(FieldName & '/', '/', 3) as Son1,

SubField(FieldName & '/', '/', 2) as Father

View solution in original post

Highlighted
Not applicable

Now everything works Thanks a lot for your time!!!