Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
elmelavi
Contributor III
Contributor III

How to add field Base By previous Data

Hay lts say I have that Data:

ITEM ID SUPLAYDATE QTYTOSUPLAY INVENTORY
123 10/02/2023 10 15
123 18/02/2023 3 15
456 18/03/2023 6 9
456 25/03/2023 2 9

 

and i need to add leftover column that considerate the item ID only

so i will have that table:

ITEM ID SUPLAYDATE QTYTOSUPLAY INVENTORY LEFT OVER
123 10/02/2023 10 15 5
123 18/02/2023 3 15 2
456 18/03/2023 6 9 3
456 25/03/2023 2 9 1

I HAVE TO DO IT IN THE SCRIPT

BR

LAVI

Labels (1)
1 Solution

Accepted Solutions
sidhiq91
Specialist II
Specialist II

@elmelavi  Please see the code below. 

NoConcatenate
temp:
Load ITEMID,
Date(date#(SUPLAYDATE,'DD/MM/YYYY'),'DD/MM/YYYY') as SUPLAYDATE,
QTYTOSUPLAY,
INVENTORY,
rowno() as Row_number

inline [
ITEMID,SUPLAYDATE,QTYTOSUPLAY,INVENTORY
123,10/02/2023, 10, 15
123,18/02/2023, 3, 15
456,18/03/2023, 6, 9
456,25/03/2023, 2, 9
];

NoConcatenate
Temp1:
load ITEMID,

Date(date#(SUPLAYDATE,'DD/MM/YYYY'),'DD/MM/YYYY') as SUPLAYDATE,
QTYTOSUPLAY,
INVENTORY,

if(Row_number='1', INVENTORY-QTYTOSUPLAY,
if(ITEMID=peek(ITEMID) ,peek(leftover)-QTYTOSUPLAY,INVENTORY-QTYTOSUPLAY) )as leftover

Resident temp;

Drop table temp;

Exit Script;

If this resolves the issue, please like and accept it as a solution.

sidhiq91_0-1675356719619.png

 

View solution in original post

4 Replies
sidhiq91
Specialist II
Specialist II

@elmelavi  Please see the code below. 

NoConcatenate
temp:
Load ITEMID,
Date(date#(SUPLAYDATE,'DD/MM/YYYY'),'DD/MM/YYYY') as SUPLAYDATE,
QTYTOSUPLAY,
INVENTORY,
rowno() as Row_number

inline [
ITEMID,SUPLAYDATE,QTYTOSUPLAY,INVENTORY
123,10/02/2023, 10, 15
123,18/02/2023, 3, 15
456,18/03/2023, 6, 9
456,25/03/2023, 2, 9
];

NoConcatenate
Temp1:
load ITEMID,

Date(date#(SUPLAYDATE,'DD/MM/YYYY'),'DD/MM/YYYY') as SUPLAYDATE,
QTYTOSUPLAY,
INVENTORY,

if(Row_number='1', INVENTORY-QTYTOSUPLAY,
if(ITEMID=peek(ITEMID) ,peek(leftover)-QTYTOSUPLAY,INVENTORY-QTYTOSUPLAY) )as leftover

Resident temp;

Drop table temp;

Exit Script;

If this resolves the issue, please like and accept it as a solution.

sidhiq91_0-1675356719619.png

 

elmelavi
Contributor III
Contributor III
Author

Thank u very much

It's exactly what I looked for

sidhiq91
Specialist II
Specialist II

@elmelavi  Glad that it worked for you. Could you please like the solution as well. Thanks in advance.

elmelavi
Contributor III
Contributor III
Author

liked