Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
luke1986
Contributor III
Contributor III

Reduce Sales with previous calculated value

Hey Folks,

Iam stuck with a problem.

The Blue Color is my sample Data and the Orange is the output that should be generated in Script. So basically i need to multiply the Sales with the % Value. The Output is "New Sales X Value", after that, i need to reduce the "New Sales" with the Previous Calculated Value. I do this until a new Key appears and start all over again. In addition, it needs to be reduce based on the calculation Order.

KeyCalculation OrderSalesValueNew SalesNew Sales X Value
A110003%100030
A210002%97019,4
A320004%950,638
B120002%200040
B220002%196039,2
B320004%1920,876,8
B420002%184436,8
C15003%50015
C25004%48519,4

I tried with a for next loop and the previous function. But i didnt manage to find  a solution.

Someone an Idea?

Lukas

1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

Here is your solution

LOAD Key,

    [Calculation Order],

    Sales,

    Value,

    if(Key=Previous(Key),(Peek(NewSales) - Peek(NewSalesXValues)) * Value,Sales*Value) as NewSalesXValues,

    if(Key=Previous(Key),Peek(NewSales) - Peek(NewSalesXValues),Sales) as NewSales

FROM

[https://community.qlik.com/thread/255635]

(html, codepage is 1252, embedded labels, table is @1);

Capture.JPG

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

5 Replies
Anil_Babu_Samineni

What was the logic for "New sales X value"?

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
luke1986
Contributor III
Contributor III
Author

Thats where it gets trickey. On every calculation Order = 1 You calculate Sales * Value. Thats how you get the first line in New Sales x Value. Then you change the calculation to (Sales - Previous(New Sales x Value)) * Value.

vinieme12
Champion III
Champion III

Here is your solution

LOAD Key,

    [Calculation Order],

    Sales,

    Value,

    if(Key=Previous(Key),(Peek(NewSales) - Peek(NewSalesXValues)) * Value,Sales*Value) as NewSalesXValues,

    if(Key=Previous(Key),Peek(NewSales) - Peek(NewSalesXValues),Sales) as NewSales

FROM

[https://community.qlik.com/thread/255635]

(html, codepage is 1252, embedded labels, table is @1);

Capture.JPG

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
luke1986
Contributor III
Contributor III
Author

Thanks Vineeth, that works!

vinieme12
Champion III
Champion III

Glad to help

Cheers

V

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.