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

Cumulative Sum for Date Range

Hello,

I have the following table:

(Date has format: DD/MM/YYYY)

DATE VALUE AUX_DATE CUMULATIVE
01/01/20175022/12/2016
02/01/20177023/12/2016
03/01/20171024/12/2016
04/01/201712025/12/2016
05/01/20171026/12/2016
06/01/20171027/12/2016
07/01/20171028/12/2016
08/01/20171029/12/2016
09/01/20171030/12/2016
10/01/20171031/12/2016
11/01/20171001/01/2017
12/01/20171002/01/2017
13/01/20171003/01/2017
14/01/20171004/01/2017
15/01/20172005/01/2017100
16/01/201715006/01/2017110
17/01/201711507/01/2017250
18/01/20171008/01/2017355
19/01/20177009/01/2017355
20/01/20178010/01/2017415
21/01/20176011/01/2017485
22/01/20173012/01/2017535
23/01/20179013/01/2017555

What I need to do is to calculate the column CUMULATIVE. For example:

The row with DATE = 15/01/2017 and AUX_DATE = 05/01/2017 has CUMULATIVE = 100

The CUMULATIVE should be the SUM of VALUE from AUX_DATE (05/01/2017) to DATE-1 (14/01/2017)

DATEVALUEAUX_DATE
05/01/20171026/12/2016
06/01/20171027/12/2016
07/01/20171028/12/2016
08/01/20171029/12/2016
09/01/20171030/12/2016
10/01/20171031/12/2016
11/01/20171001/01/2017
12/01/20171002/01/2017
13/01/20171003/01/2017
14/01/20171004/01/2017

The row with DATE = 16/01/2017 and AUX_DATE = 06/01/2017 has CUMULATIVE = 110

The CUMULATIVE should be the SUM of VALUE from AUX_DATE (06/01/2017) to DATE-1 (15/01/2017)

DATEVALUEAUX_DATE
06/01/20171027/12/2016
07/01/20171028/12/2016
08/01/20171029/12/2016
09/01/20171030/12/2016
10/01/20171031/12/2016
11/01/20171001/01/2017
12/01/20171002/01/2017
13/01/20171003/01/2017
14/01/20171004/01/2017
15/01/20172005/01/2017

Do you know how could I do this on Script?

Thank you!!!

1 Solution

Accepted Solutions
maxgro
MVP
MVP

in image the result, look at the attachment

1.png

A:

LOAD DATE,

     VALUE,

     AUX_DATE

     //CUMULATIVE

FROM

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

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

B:

load

  DATE,

  Date(AUX_DATE + IterNo() -1) as DATE2

Resident A

While Date(AUX_DATE + IterNo() -1) <= (DATE -1);

Left Join (B)

LOAD

  DATE as DATE2,

  VALUE as VALUE2

Resident A;

Left join (A)

LOAD DATE, sum(VALUE2) as CUMULATIVE

Resident B

Group By DATE;

// you can drop table B here

View solution in original post

1 Reply
maxgro
MVP
MVP

in image the result, look at the attachment

1.png

A:

LOAD DATE,

     VALUE,

     AUX_DATE

     //CUMULATIVE

FROM

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

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

B:

load

  DATE,

  Date(AUX_DATE + IterNo() -1) as DATE2

Resident A

While Date(AUX_DATE + IterNo() -1) <= (DATE -1);

Left Join (B)

LOAD

  DATE as DATE2,

  VALUE as VALUE2

Resident A;

Left join (A)

LOAD DATE, sum(VALUE2) as CUMULATIVE

Resident B

Group By DATE;

// you can drop table B here