Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
andre_ficken
Partner - Creator
Partner - Creator

Calculate balance per product over periods

I have a table holding product,year and period as well as stockposition,purchase qty and sales qty. the number of periods varies by product, since sales and purchase varies by product.Stock is always recorded at the current period. There is no constant number of year and period records. The table is sorted by product, year and period.

The table roughly looks like this:

product, year,      period,      stock, purchase, sales, balance

A,          2011,     10,          100,     50,          175,    -25

A,          2011,     11,          0,        50,          100,    -75

B,          2011,     10,          25,       5,           15,      15

B,          2011,     11,          0,         0,           20,      -5

B,          2011,     12,          0,         50,         30,      15

C,          2011,     10,          5,         0,           0,       5

C,          2012,     02,          0          15,         20,      0

What I want to do is to calculate the balance over time per year and period so the balance for the first line per product is stock+ purchase - sales.

The next line for the same product it should start with the balance of the previous line + purchase - sales = balanace. This should be continued until the product changes. It should then start again calculating the balance for the first line (stock + purchase - sales) and continue with the next line from the table.

Is there an easy way to get this done?? Thanks for any advice and/or help.

7 Replies
spividori
Specialist
Specialist

Hi.

See the attached example.

Hope this help.

Regards.

Not applicable

ehh, can't open it in free version. Can you safe you attached example for free version qlikview? thnx in advance.

spividori
Specialist
Specialist

Hi.

I have no idea how to save the file to see it in the free version.

Script:

Table:

Captura1.JPG

Regards.

spividori
Specialist
Specialist

Sorry, here the script:

Captura.JPG

Regards.

Phan_Anh_Son
Partner - Contributor III
Partner - Contributor III

script not working help me to correct

Thanks.

spividori
Specialist
Specialist

Hi.

See de atach.

Regards.

Phan_Anh_Son
Partner - Contributor III
Partner - Contributor III

Thanks for your help.