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

Get the index of a subfield row

Hello,

When using Subfield() without a specified index, the cartesian product is generated and there is a new row for each subfield value.

The problem I'm having is that I can't identify which index each row relates to.

Are they guaranteed to be in order? Is there a function I can use to identify which subfield index the row refers to?

The source system I'm working with has up to 30 subfields in one field so bit of a nightmare.

 

Thank you.

Labels (6)
3 Replies
edwin
Master II
Master II

Try this:

load
Player,
Project,
Project2,
SubStringCount(left(Project,Index(Project,Project2)),',')+1 as Position,
Index(Project,Project2) as Index;

//these two load statements are from the documentation for subfield---
LOAD DISTINCT
Player,
Project,
SubField(Project,',') as Project2;

Load * inline [
Player|Project
Neil|Music,OST
Jo|Music
Mike|Music,OST,Video
] (delimiter is '|');

 

Index gives you the position in number of chars of the subfield.  then you just count your delimiters before that position. 

marcus_sommer

You could combine subfield() with a while-loop to get this index from iterno(), for example like:

// load *, rowno() as RowNo, recno() as RecNo;
load iterno() as IterNo, Field, subfield(Field, YourDelimiter, iterno()) as FieldPart
from Source while iterno() <= substringcount(YourDelimiter) +1;

- Marcus

 

Brett_Bleess
Former Employee
Former Employee

You have been provided with two ideas, we would greatly appreciate it if you would close out the thread and mark the post(s) that helped by using the Accept as Solution button on the one(s) that did help you resolve things.  If you did something different, consider posting what you did and then after you post it, use the button to mark it as the solution to close the thread.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.