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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sum based on condition

Hi all,

Need your help as I tried everything and gave up..

My problem is to sum of forecast sales numbers for rest of the months for each project ID.

Following is the data I have

IDDateSale
1011/March/201710
1012/March/201720
1013/March/201710
1014/March/201710
1025/March/201720
1026/March/201710
1027/March/201720

Answer-set should look like: Summing all Dates Sales data for individual ID and for next date ignoring the previous date and summing what rest is left

IDDateResult
1011/March/201750
1012/March/201740
1013/March/201720
1014/March/201710
1025/March/201750
1026/March/201730
1027/March/201720

I hope to get some guidance I tried everything and not reaching anywhere.

1 Solution

Accepted Solutions
pokassov
Specialist
Specialist

Hello

In script:

[sum forecasts]:

load

  ID,

  Date,

  RangeSum(if(previous(ID)=ID, peek(Result),0),Sale)     As Result

Resident forecasts

Order by ID,

     Date desc;

View solution in original post

8 Replies
pokassov
Specialist
Specialist

Hello

In script:

[sum forecasts]:

load

  ID,

  Date,

  RangeSum(if(previous(ID)=ID, peek(Result),0),Sale)     As Result

Resident forecasts

Order by ID,

     Date desc;

Anil_Babu_Samineni

May be use this for result

If(Above(Aggr(Sum(Sale),ID),0),Above(Aggr(Sum(Sale),ID),0),Above(Result - Sum(Sale),1,3))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

Use this expression in result

Rangesum(Below(sum(Sale),0,count(total<ID> Sale)+1-RowNo()))

Not applicable
Author

Hi Sergey

Thanks heaps. It worked. Appreciate if you please help in understanding what is happening in this function so I can use it in future.

Regards

Not applicable
Author

Thanks Anil

Not applicable
Author

Thanks Shiva

pokassov
Specialist
Specialist

Hi John

When we use a resident load we can use clause "Order By"

So all of your data will be correctly (as we need) ordered

Function previous uses value of a field from previous row of the resulting table.

Function peek is almost the same, but you can use value from a new field that can be generated by the load.

RangeSum simply sums two argument.

But it's convinient for situations when one of the arguments is null - the result won't be null.

Best regards, Sergey

Not applicable
Author

Thanks heaps Sergey.. Appreciate your help.