Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Madina
Contributor III
Contributor III

take previous and next rows from current in load script

Hello,

I have table customer with columns date, amount, type

date, amount, type

january23, 100, 1

february23, 200, 1

march23, 400, 2

april23, 700,1

What I want is to have next table customer2

date, amount

where depending on type, you choose to write original amount from previous date of current, if type is 1,

and if type is 2, write original amount from next date from current

january23, null

february23, 100

march23, 700

april23, null

Regards, Madina
Labels (5)
1 Solution

Accepted Solutions
Ahidhar
Creator III
Creator III

try this

tab:
load * Inline
[
date, amount, type

january23, 100, 1

february23, 200, 1

march23, 400, 2

april23, 700,1
];

tab1:
load
date,
if(type=1,previous(amount),
peek('amount',recno(),'tab')) as amount
resident tab; drop table tab;

View solution in original post

2 Replies
Ahidhar
Creator III
Creator III

try this

tab:
load * Inline
[
date, amount, type

january23, 100, 1

february23, 200, 1

march23, 400, 2

april23, 700,1
];

tab1:
load
date,
if(type=1,previous(amount),
peek('amount',recno(),'tab')) as amount
resident tab; drop table tab;

Chanty4u
MVP
MVP

try this

If(Type = 1, Peek('Amount', -1), null()) as Amount