Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
simonagheo
Contributor III
Contributor III

Sum while less than equal another field

Hello,

I have an Acquisition table and a Stock one like the ones below.

I want to obtain a field that contains the most recent Invoice numbers for every item, until the stock value is obtain or is overfulfilled, and another field that sums the quantity of that invoices.

Acquisitions
InvNo InvDate ItemNo QtyAcq
I1 03.03.2024 A1 1
I2 05.10.2024 A1 2
I3 06.11.2024 A1 2
I4 02.04.2024 A2 2
I5 06.05.2024 A2 1
I6 08.09.2024 A2 5

 

Stock
ItemNo QtyStock
A1 3
A2 5

 

For the example above, I want to obtain InvAcq and Sum(QtyAcq).

ItemNo Sum(QtyAcq) InvAcq
A1 4 I2, I3
A2 5 I6

 

Please help me to solve the problem.

Thank you,

Teodora

 

Labels (1)
1 Solution

Accepted Solutions
Kushal_Chawda

@simonagheo  I would use below script

Data:
Load * Inline [
InvNo	InvDate	ItemNo	QtyAcq
I1	03.03.2024	A1	1
I2	05.10.2024	A1	2
I3	06.11.2024	A1	2
I4	02.04.2024	A2	2
I5	06.05.2024	A2	1
I6	08.09.2024	A2	5
](delimiter is '\t');

Left Join(Data)
Load * Inline [
ItemNo	QtyStock
A1	3
A2	5
](delimiter is '\t');

T1:
NoConcatenate
Load *,
     if(ItemNo=Previous(ItemNo),rangesum(Peek('AccumQtyAcq'),QtyAcq) ,QtyAcq) as AccumQtyAcq
Resident Data
Order by ItemNo,InvDate;

Drop Table Data;

Final:
NoConcatenate
Load *,
     if(AccumQtyAcq>=QtyStock,1,0) as Flag
Resident T1;

drop table T1;

 

Create table with Dimension ItemNo and below two measures

=Concat({<Flag={1}>}InvNo,',') // Invoice

=sum({<Flag={1}>}QtyAcq) //Qty Acq

 

Screenshot 2024-11-06 at 11.11.24.png

View solution in original post

1 Reply
Kushal_Chawda

@simonagheo  I would use below script

Data:
Load * Inline [
InvNo	InvDate	ItemNo	QtyAcq
I1	03.03.2024	A1	1
I2	05.10.2024	A1	2
I3	06.11.2024	A1	2
I4	02.04.2024	A2	2
I5	06.05.2024	A2	1
I6	08.09.2024	A2	5
](delimiter is '\t');

Left Join(Data)
Load * Inline [
ItemNo	QtyStock
A1	3
A2	5
](delimiter is '\t');

T1:
NoConcatenate
Load *,
     if(ItemNo=Previous(ItemNo),rangesum(Peek('AccumQtyAcq'),QtyAcq) ,QtyAcq) as AccumQtyAcq
Resident Data
Order by ItemNo,InvDate;

Drop Table Data;

Final:
NoConcatenate
Load *,
     if(AccumQtyAcq>=QtyStock,1,0) as Flag
Resident T1;

drop table T1;

 

Create table with Dimension ItemNo and below two measures

=Concat({<Flag={1}>}InvNo,',') // Invoice

=sum({<Flag={1}>}QtyAcq) //Qty Acq

 

Screenshot 2024-11-06 at 11.11.24.png