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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sum 3 past months (into script)

ProductDateSales
Product A1/1/2008200
Product A2/1/200835
Product A3/1/2008562
Product A4/1/20085562
Product A5/1/20085423
Product A6/1/200832
Product A7/1/200832
Product A8/1/2008466
Product A9/1/2008216
Product A10/1/2008129
Product A11/1/20082654
Product A12/1/2008265
Product B1/1/20083235
Product B2/1/20082362
Product B3/1/2008232
Product B4/1/2008454
Product B5/1/2008569
Product B6/1/200857
Product B7/1/20084
Product B8/1/2008489
Product B9/1/20085489
Product B10/1/20085121


I need to run a script in order to accumulate subtotal for the last 3 monhts, like this:

ProductDateSales
Product A1/1/2008200Sum Jan+Dec(2007)+Nov(2007)
Product A2/1/2008356159
Product A3/1/200856211547
Product A4/1/2008556211017
Product A5/1/200854235487
Product A6/1/200832530
Product A7/1/200832714
Product A8/1/2008466811Sum Aug+Jul+Jun (3month acculumation)
Product A9/1/20082162999Sum Sep +Aug+Jul (3monht accumulation)


-------------------------------------------------------------------------------------------------------------------------

LOAD Product,
Date,
Year(Date) as Year,
Month(Date) as Month,
date(Date, 'MMM-YYYY' ) as MonthYear,
MonthName(Date) as MonthName,
Sales
FROM
//I need to run a script in order to accumulate subtotal for the last 3 monhts, like this:
//Jan2008 would be the SUM of Jan2008+Dec2007+Nov2007
//Feb2008 '' '' '' '' '' Feb2008+Jan2008+Dec2007
//Note that I have 2 different products

QVD file attached.

THANKS

1 Reply
GabrielAraya
Employee
Employee

Hi, Did you test the Previous function?

Directory;







Test:

LOAD

Product ,

Date

,

Amount

FROM

Prueba.xlsx

(ooxml, embedded labels, table is Sheet1);

Final:

Load

Product

,

Date

,

Amount

,

If

(Product = Previous(Product),

RangeSum

(Amount,Previous(Amount),Previous(Previous(Amount))), Amount) as Acc

Resident

Drop

Table

Test;

Test;