Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
PRO_11
Contributor II
Contributor II

QlikSense Trailing 30 days sum for given date in table group by id

Sample Data:

customer_ID  DATE         qty
97                 9/22/2021     25
97              1/24/2022      190
97            1/25/2022        9
97          2/24/2022        20
97          2/25/2022       56
93          6/5/2020          8
93        8/3/2020         23
93        8/4/2020          8
93         8/6/2020         3
93        12/17/2020    15
93        12/21/2020      1
93          2/4/2021        9
93          2/8/2021        4
93           9/9/2021        4
93          1/7/2022         7
93          2/15/2022      44
93         2/18/2022      50

For each Cust id and date , I need sum the value for last 30 days(for those dates purchase is made) like below table i have to create calculative column Trailing 30 days qty.  

if no previous dates fall in 30 days than have same value.  I am able to do that on expression but i need to create column on load script: 

sum({$< DATE = {"$(='>=' & Date(DATE -30) & '<=' & Date(DATE))"}>} qty)

sum({$< DATE = {"$(='>=' & 12/26/2021 & '<=' & 01/25/2022"}>} qty)  

Means for data 1/25/2022 the sum up the value from 12/26/2021 so 190+99

if 2/24/2022 then whatever dates fall for last 30 days to sum so 190+9+20 so on for each group of ID i have check on dates and sum for last 30 days. I tried intervalmatch but did not get the desired results. 

PRO_11_1-1651352578027.png

Thank you in advance.   let me know if any question

PRO

Labels (5)
2 Solutions

Accepted Solutions
vinieme12
Champion III
Champion III

In your example, the 1/7/2022 is way beyond the 30days limit but still being accumulated to 2/18/2022!!

qlikCommunity.PNG

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

PRO_11
Contributor II
Contributor II
Author

@vinieme12 

Many Thanks. your solution worked. yes thats my calculation mistake. 

View solution in original post

5 Replies
vinieme12
Champion III
Champion III

Create an AsOF table as below

 

Table1:
Load *,customer_ID&'-'&DATE as Key inline [
customer_ID,DATE,qty
97,9/22/2021,25
97,1/24/2022,190
97,1/25/2022,9
97,2/24/2022,20
97,2/25/2022,56
93,6/5/2020,8
93,8/3/2020,23
93,8/4/2020,8
93,8/6/2020,3
93,12/17/2020,15
93,12/21/2020,1
93,2/4/2021,9
93,2/8/2021,4
93,9/9/2021,4
93,1/7/2022,7
93,2/15/2022,44
93,2/18/2022,50
];


AsOf:
Load *
Where Exists(DATE,AsOfDate);
Load
customer_ID as customer_ID2
,DATE as DATE2
,customer_ID&'-'&Date(DATE - Iterno()+1) as Key
,Date(DATE - Iterno()+1) as AsOfDate
Resident Table1
While DATE-32 <= DATE - Iterno()+1;


exit Script;

 

In Chart:

Dimension: customer_ID, DATE

Measure:

Qty = Sum(qty)

30 Days Trailing Qty =  sum(aggr(Sum(qty),customer_ID2,DATE2))

 

qlikCommunity1.PNG

 

 

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
vinieme12
Champion III
Champion III

In your example, the 1/7/2022 is way beyond the 30days limit but still being accumulated to 2/18/2022!!

qlikCommunity.PNG

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
PRO_11
Contributor II
Contributor II
Author

@vinieme12 

Many Thanks. your solution worked. yes thats my calculation mistake. 

PRO_11
Contributor II
Contributor II
Author

@vinieme12 
if I would like to do sum for previous months only do I use IterNO() -1?  I used >= start(lastmonth )and  <= Enddate(LastMonth)

 

PRO_11_1-1651879127020.png

Your response is very useful but still not understanding  Iterno() 

PRO_11
Contributor II
Contributor II
Author

 Thank you @vinieme12  Its helpfull but still not understanding  IterNo()

Like to sum for only previous month qty. just for my learning.  How does as-of work on on previous month.

PRO_11_4-1651879456125.png