Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
fnfrbr95
Contributor II
Contributor II

How to create a Key Field in a Text File - One Too Many

Hey Guys!

 

I need help!

 

I have data in a text file, like this:

 

|REG1|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG1|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG1|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

|REG2|INFO|INFO|INFO|INFO|INFO|

 

 

This go on by an N number of lines, can exceed a million rows.

 

The thing is, I will always have a |REG1| and N numbers of |REG2|, they are parent.

 

What I want too achieve in Qlik is something like this:

 

|1|REG1|INFO|INFO|INFO|

|1|REG2|INFO|INFO|INFO|INFO|INFO|

|1|REG2|INFO|INFO|INFO|INFO|INFO|

|1|REG2|INFO|INFO|INFO|INFO|INFO|

|2|REG1|INFO|INFO|INFO|

|2|REG2|INFO|INFO|INFO|INFO|INFO|

|2|REG2|INFO|INFO|INFO|INFO|INFO|

|2|REG2|INFO|INFO|INFO|INFO|INFO|

|2|REG2|INFO|INFO|INFO|INFO|INFO|

|2|REG2|INFO|INFO|INFO|INFO|INFO|

|3|REG1|INFO|INFO|INFO|

|3|REG2|INFO|INFO|INFO|INFO|INFO|

|3|REG2|INFO|INFO|INFO|INFO|INFO|

 

I been trying to do this all day and couldn't get it done, but seems to be so simple.

 

Can anyone help me?

Labels (5)
1 Solution

Accepted Solutions
Vegar
MVP
MVP

Maybe this will  script will help you: 

LOAD if(B='REG1',alt(peek('Reg1New'),0)+1,peek('Reg1New')) as Reg1New, *

inline [
A|B|C|D|E|F
1|REG1|INFO|INFO|INFO|
2|REG2|INFO|INFO|INFO|INFO|INFO|
3|REG2|INFO|INFO|INFO|INFO|INFO|
4|REG2|INFO|INFO|INFO|INFO|INFO|
5|REG1|INFO|INFO|INFO|
6|REG2|INFO|INFO|INFO|INFO|INFO|
7|REG2|INFO|INFO|INFO|INFO|INFO|
8|REG2|INFO|INFO|INFO|INFO|INFO|
9|REG2|INFO|INFO|INFO|INFO|INFO|
10|REG2|INFO|INFO|INFO|INFO|INFO|
11|REG1|INFO|INFO|INFO|
12|REG2|INFO|INFO|INFO|INFO|INFO|
13|REG2|INFO|INFO|INFO|INFO|INFO|
] (delimiter is |);

 

It will give you this table:

image.png

View solution in original post

2 Replies
Vegar
MVP
MVP

Maybe this will  script will help you: 

LOAD if(B='REG1',alt(peek('Reg1New'),0)+1,peek('Reg1New')) as Reg1New, *

inline [
A|B|C|D|E|F
1|REG1|INFO|INFO|INFO|
2|REG2|INFO|INFO|INFO|INFO|INFO|
3|REG2|INFO|INFO|INFO|INFO|INFO|
4|REG2|INFO|INFO|INFO|INFO|INFO|
5|REG1|INFO|INFO|INFO|
6|REG2|INFO|INFO|INFO|INFO|INFO|
7|REG2|INFO|INFO|INFO|INFO|INFO|
8|REG2|INFO|INFO|INFO|INFO|INFO|
9|REG2|INFO|INFO|INFO|INFO|INFO|
10|REG2|INFO|INFO|INFO|INFO|INFO|
11|REG1|INFO|INFO|INFO|
12|REG2|INFO|INFO|INFO|INFO|INFO|
13|REG2|INFO|INFO|INFO|INFO|INFO|
] (delimiter is |);

 

It will give you this table:

image.png

fnfrbr95
Contributor II
Contributor II
Author

Good morning Vegar!

 

This worked like a charm!

 

Thank you so much!