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: 
oscarvictory
Contributor III
Contributor III

Accumulative sum leaser or first greater than value

Hi all, maybe you can help me out with this question.

Here is my table from SQL:

Table_1.jpg

and what I need is to display only the rows where ACUM sum includes STOCK amount:

Table_2.jpg

 Many TKS in advance.

Labels (1)
1 Solution

Accepted Solutions
Kushal_Chawda

@oscarvictory  try below. Highlighted in Green you can replace it with measure you want to show. Suppose you want to show ACCUM , so replace it with below

sum(aggr(rangesum(above(total Sum(Qty),0,RowNo())), PRODUCT,(RCV_DATE,(NUMERIC,DESCENDING))))

 

=if(aggr(rangesum(above(total Sum(Qty),0,RowNo())), PRODUCT,(RCV_DATE,(NUMERIC,DESCENDING))) <= min(total <PRODUCT>aggr(if(rangesum(above(total Sum(Qty),0,RowNo())) > = sum(STOCK),rangesum(above(total Sum(Qty),0,RowNo()))), PRODUCT,(RCV_DATE,(NUMERIC,DESCENDING)))),
Sum(Stock),0)

View solution in original post

11 Replies
Kushal_Chawda

@oscarvictory  Is the ACCUM and STOCK are measure in chart or fields in table?

oscarvictory
Contributor III
Contributor III
Author

Hi Kushal, they are just fields in the table.

oscarvictory
Contributor III
Contributor III
Author

In fact I did try:

if( Aggr(RangeSum(above(Sum( STOCK) , 0, RowNo(TOTAL))),PRODUCT, STOCK ) > ACUM, STOCK )

But it did not work.

Kushal_Chawda

@oscarvictory  I see that for all product , you have used RCV_DATE descending to compare  ACCUM with STOCK, but for last product first Date should be 01/11/2021 so shouldn't it be 12 instead of 4?

oscarvictory
Contributor III
Contributor III
Author

You are right, you can dismiss the last line, it was added manually in order to enlarge the sample. But obvuiously date is wrong.

Kushal_Chawda

@oscarvictory  try below expression with Product and rcv_date as dimension. Below is the expression for ACCUM. If you have other measures in table, you need to  replace highlighted part with that measure expression so that when you uncheck "Include zero value" (Qlik sense) or "suppress zero value" (QlikView) it will show the relevant rows

=if(aggr(rangesum(above(total Sum(ACCUM),0,RowNo())), PRODUCT,(RCV_DATE,(NUMERIC,DESCENDING))) <= min(total <PRODUCT>aggr(if(rangesum(above(total Sum(ACCUM),0,RowNo())) > sum(STOCK),rangesum(above(total Sum(ACCUM),0,RowNo()))), PRODUCT,(RCV_DATE,(NUMERIC,DESCENDING)))),
Sum(ACCUM),0)

 

oscarvictory
Contributor III
Contributor III
Author

I have replaced the red expression by Sum(STOCK) because is the correct one, but it seems that something is wrong.

In this example it should have taken the three first rows = ACCUM 11, but is only taking two:

Table_1.jpg

Table_2.jpg

Kushal_Chawda

@oscarvictory  As per your example, is it not 5+10=15 which is already more than stock so should be two lines? In your original post example as well for product 98654, (2+5+7 =14) which is more than stock 8. Am I missing something?

oscarvictory
Contributor III
Contributor III
Author

Yes 😁, I will try to explain better.

ACCUM means:Table_3.jpg

So, if STOCK is 11 it must take the first three lines, if STOCK was 12 it should include the fourth line.