Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a table with date, customer, quantity and I need to know the variation amount from the previous date
DATE | CUSTOMER | QUANTITY |
---|---|---|
2016-01-01 | 3 | 125 |
2016-01-03 | 3 | 148 |
2016-01-07 | 2 | 480 |
2016-01-12 | 1 | 85 |
2016-01-21 | 3 | 198 |
EXAMPLE: CUSTOMER 3 ON 21TH -> 198-148= 50
If you want to calculate this in the script:
Result:
LOAD
Customer,
Date,
Quantity,
If(Previous(Customer) = Customer, Quantity- Previous(Quantity) ) as Diff
RESIDENT YourTable
ORDER BY Customer, Date;
DROP Table YourTable;