Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

split one field into many i.e subfield delimited etc

Hi

I have a field which shows all "ProblemTypes" we log maintainance work against.  Although the problem types are are stored in a single field they actually belong in a hierarchy which is shown in the "HierarchyTrace" field from the same table.  Both fields are pulled in from a SQL data base into my QV model via QVD loader file.

What I'd like to do (in the loader script) is to split out the "HierarchyTrace" field, into the various hierarchy levels for the problem types.

So for example we could have a problems type of:

"Electrical"

"Light"

"Light-Fail"

"Light-Damage"

The last 3 are sub types of the "Electrical" problem type, in fact the 2nd one would be the 2nd level of the hierarchy, the 3rd & 4th items in this example would both be in the 3rd level of the hierarchy.

The "HierarchyTrace" field lists this as follows (for example):

Electrical|

Electrical|Light|

Electrical|Light|Light-Fail|

Electrical|Light|Light-Damage|

Notice the | character  is the delimiter!

So what I want to create would be for example:

ProblemTypeHierarchyTraceHierachyLevel1HierachyLevel2HierachyLevel3
ElectricalElectrical|Electrical--
LightElectrical|Light|ElectricalLight-
Light-FailElectrical|Light|Light-Fail|ElectricalLightLight-Fail
Light-DamageElectrical|Light|Light-Damage|ElectricalLightLight-Damage

I'm not sure best way to go about doing this, I'm guessing it may be using subfield, loops etc???

Attached are sample of the qvw with the fields mentioned above and excel file showing how I've used the delimiter to split the "HierarchyTrace" field into 3 columns etc

any help would be great, thanks

Dan

1 Solution

Accepted Solutions
Not applicable
Author

Hi Dan,

you have already come up with the solution in using subfield, you just need to expand that now to create the fields you require, from the right subfield position you need

SubField([Hierarchy Trace],'|',1) AS Hierarchy_Level1
,
SubField([Hierarchy Trace],'|',2) AS Hierarchy_Level2
,
SubField([Hierarchy Trace],'|',3) AS Hierarchy_Level3

hope that helps

Joe

View solution in original post

3 Replies
Not applicable
Author

Hi Dan,

you have already come up with the solution in using subfield, you just need to expand that now to create the fields you require, from the right subfield position you need

SubField([Hierarchy Trace],'|',1) AS Hierarchy_Level1
,
SubField([Hierarchy Trace],'|',2) AS Hierarchy_Level2
,
SubField([Hierarchy Trace],'|',3) AS Hierarchy_Level3

hope that helps

Joe

Not applicable
Author

i was thinking it'll be more complex than that but happy simple solution worked

just need to add quotes like  '|' around the delimiter character!

Dan

Not applicable
Author

whoops how did I miss that there! Have edited now for anyone else reading

glad to help