Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
jduluc12
Creator
Creator

Load script question

 Hi,

My data looks like this.

Id        Name       Type      Price

1           X                G             10     

2           B                T             20

3           C                M             20

4           -                 -                -

5           Y               G              22

6           B               T               23

7           D               C               20

8           -                -                  -  

9          D               N               50

Now I want to add a new column "Link" to make data looks like as following:

Id        Name       Type      Price           Link

1           X                G             10                 1

2           B                T             20                 1

3           C                M            20                 1

4           -                 -                -

5           Y               G                22              5

6           B               T               23               5

7           D               C               20               5

8           -                -                  -  

9          D               N               50

The script should look for the rows with Type "G" and should iterate over the subsequent rows to add the Id of Type "G" in the new column "Link" until it finds a NULL row like the row with ID "4" and "8".

 

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar

My bad, it will be this

Table:
LOAD *,
	 If(Type = 'G', Id, If(Len(Trim(Type)) = 0, ' ', Peek('Link'))) as Link;
LOAD * INLINE [
    Id, Name, Type, Price
    1, X, G, 10
    2, B, T, 20
    3, C, M, 20
    4
    5, Y, G, 22
    6, B, T, 23
    7, D, C, 20
    8
    9, D, N, 50
];

View solution in original post

4 Replies
sunny_talwar

Try this

Table:
LOAD *,
	 If(Type = 'G', RangeSum(Peek('Link'), 1), If(Len(Trim(Type)) = 0, ' ', Peek('Link'))) as Link;
LOAD * INLINE [
    Id, Name, Type, Price
    1, X, G, 10
    2, B, T, 20
    3, C, M, 20
    4
    5, Y, G, 22
    6, B, T, 23
    7, D, C, 20
    8
    9, D, N, 50
];
jduluc12
Creator
Creator
Author

If(Type = 'G', RangeSum(Peek('Link'), 1), If(Len(Trim(Type)) = 0, ' ', Peek('Link'))) as Link;
should be
If(Type = 'G', RangeSum(Peek('Id'), 1), If(Len(Trim(Type)) = 0, ' ', Peek('Id'))) as Link;
?
sunny_talwar

My bad, it will be this

Table:
LOAD *,
	 If(Type = 'G', Id, If(Len(Trim(Type)) = 0, ' ', Peek('Link'))) as Link;
LOAD * INLINE [
    Id, Name, Type, Price
    1, X, G, 10
    2, B, T, 20
    3, C, M, 20
    4
    5, Y, G, 22
    6, B, T, 23
    7, D, C, 20
    8
    9, D, N, 50
];
pradosh_thakur
Master II
Master II

Sample_Table:
load *,if(Type='G',RowNo(),IF(Len(Trim(Type))=0, ' ',peek(Link) )) as Link
Inline [
Id,Name,Type,Price
1 ,X,G,10
2,B,T,20
3,C,M,20
4,,,
5,Y,G,22
6,B,T,23
7,D,C,20
8,,,
9,D,N,50
];

Learning never stops.