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: 
Rsaiq
Creator
Creator

Add amount in new field by looking previous record amount in qliksense

Hi All,

I need to create a field as New_Amount from qliksense script  by adding previous record per id.

I am sharing the dataset and Expected result for more clarifications

My Dataset:

Rsaiq_0-1673700887563.png

 

Expected Result:

Rsaiq_1-1673700955765.png

 

Please find sample data in the attachment.

Thanks in advance.

 

Labels (2)
2 Solutions

Accepted Solutions
maxgro
MVP
MVP

Try this

 

tmp:
LOAD ID,
    Date_1,
    Date_2,
    Status,
    Amount
FROM
    .......  

;

 

T:
load
    *,
    If(ID=Peek('ID'), Peek('Amount')) as New_Amount   // get the previous Amount only if ID = previous ID 
Resident tmp
order by ID, Date_2;  //  I think you want the previous amount sorting by Date_2

drop table tmp;

View solution in original post

ogster1974
Partner - Master II
Partner - Master II

This should give you what you're looking for.

LOAD
ID,
Date_1,
Date_2,
Status,
Amount,
If(ID=Previous(ID),Previous(Amount),0) as New_Amount
FROM [lib://DataFiles/Sample Data.xlsx]
(ooxml, embedded labels, header is 1 lines, table is Sheet1);

ogster1974_0-1673710226388.png

 

View solution in original post

2 Replies
maxgro
MVP
MVP

Try this

 

tmp:
LOAD ID,
    Date_1,
    Date_2,
    Status,
    Amount
FROM
    .......  

;

 

T:
load
    *,
    If(ID=Peek('ID'), Peek('Amount')) as New_Amount   // get the previous Amount only if ID = previous ID 
Resident tmp
order by ID, Date_2;  //  I think you want the previous amount sorting by Date_2

drop table tmp;

ogster1974
Partner - Master II
Partner - Master II

This should give you what you're looking for.

LOAD
ID,
Date_1,
Date_2,
Status,
Amount,
If(ID=Previous(ID),Previous(Amount),0) as New_Amount
FROM [lib://DataFiles/Sample Data.xlsx]
(ooxml, embedded labels, header is 1 lines, table is Sheet1);

ogster1974_0-1673710226388.png