5 Replies Latest reply: Apr 1, 2017 5:48 AM by Vineeth Pujari

# 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

• ###### Re: Reduce Sales with previous calculated value

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

• ###### Re: Reduce Sales with previous calculated value

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.

• ###### Re: Reduce Sales with previous calculated value

[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

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

• ###### Re: Reduce Sales with previous calculated value

Thanks Vineeth, that works!