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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Prog
Contributor II
Contributor II

Load data that exists between pairs of rows

Hi there,

I have a table like the following (generalised data):

Positions:

Position String
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 a
9 h
10

d

 

With an extract of relevant pairs as follows (assume that a and d are pairs that indicate the start and end of relevant data):

Pairs:

Position String StringCount
1 a 1
4 d 1
8 a 2
10 d 2

 

These tables continue for multiple rows, and there are multiple instances of "a" and "d" with data in between.

The positions and counts of a and d can change depending on the source data.

I wish to load the above table but include the data that appears between the pairs, i.e:

Pairs:

Position String
1 a
2 b
3 c
4 d
8 a
9 f
10

d

 

What is the easiest way to solve this? I figure I might be able to use a loop that relies on the StringCount, but wondering what ideas you have.

 

 

Cheers,

Prog

Labels (1)
1 Reply
Prog
Contributor II
Contributor II
Author

How I solved this using a loop:

Let vPairAmount = Peek('StringCount',-1,'Pairs');

For i = 1 to $(vPairAmount)

Concatenate (Pairs)
Load
Position,
String
Resident Positions
Where Position > Peek('Position',$(i)+$(i)-2,'Pairs') and Position < Peek('Position',$(i)+$(i)-1,'Pairs');

Next i;