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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
JoshPark
Contributor III
Contributor III

Accumulation of value in last x days for each day

Hello everyone, 

We have purchased licenses for Qlik Sense Enterprise SaaS. 
I'm not really the technical guy but I'm trying to find solution to calculate the accumulation of value (quantity, sales,...) in last x days for each day. 

Here is the sample data: 

Linh_Ngo_0-1673849391182.png

I want to add a measure to show: 
- Qty of last 7 days from today is: 0+0+10+6+3+10+2 = 31 
- Qty of last 7 days from yesterday is: 0+10+6+3+10+2+0 = 31
- Qty of last 7 days from 14 Jan is: 10+6+3+10+2+0+5 = 36 
- Qty of las 7 days from 13 Jan is: 6+3+10+2+0+5+14 = 40
... (get all results for each day)

Does anyone have a solution?

Thank you!

Labels (4)
1 Solution

Accepted Solutions
SerhanKaraer
Creator III
Creator III

SET DateFormat='M/D/YY';

LOAD * INLINE [
Date, Qty
1/15/23, 0
1/14/23, 0
1/13/23, 10
1/12/23, 6
1/11/23, 3
1/10/23, 10
1/9/23, 2
1/8/23, 0
1/7/23, 5
1/6/23, 14
1/5/23, 26
1/4/23, 4
];

SerhanKaraer_0-1673891163349.pngSerhanKaraer_1-1673891182105.png

SerhanKaraer_2-1673891271723.png

Given a sort, Above function creates a range of rows specified as parameters, in this case 0 offset and 7 rows below.

Aggr(RangeSum(Above(Sum("Qty (A)"),0,7)),(Date,(NUMERIC,ASCENDING)))

You can get the same result by changing sort and direction for rows.

Aggr(RangeSum(Below(Sum("Qty (A)"),0,7)),(Date,(NUMERIC,DESCENDING)))

 You have to define it in a aggr function as when user changes the sort by pressing the title in the chart, your expression may execute wrong.

View solution in original post

7 Replies
SerhanKaraer
Creator III
Creator III

Hello Linh,

Use this as a measure.

Aggr(RangeSum(Above(Sum("Qty (A)"),0,7)),(Date,(NUMERIC,ASCENDING)))

 

ogster1974
Partner - Master II
Partner - Master II

Try

RangeSum(Above([Qty],0,7))

JoshPark
Contributor III
Contributor III
Author

Hi @SerhanKaraer ,

Thank you so much for your suggestion! 

Could you share the document of the expressions which you use so I can understand the logic of the formula?

Because I think your solution seems the right method to follow; however, the expected result maybe one line different. 

Linh_Ngo_1-1673883039497.png

That's why I want to study the expression to adjust it. 

Thank you so much!

khaoulaaa
Partner - Contributor III
Partner - Contributor III

Hello,

And if you try the accumulation property 

khaoulaaa_0-1673883424551.png

 

 

JoshPark
Contributor III
Contributor III
Author

Hi @khaoulaaa 

Thank you for your comment!

I also read the documentation on Accumulation function under Modifier. 

However my measure just show these 2 options:

Linh_Ngo_0-1673883697265.png

I have already created a case prior to this topic to ask where I have done wrong and still waiting for the support. 

In case you have any idea to fix it, please kindly share it.

Thank you so much!

khaoulaaa
Partner - Contributor III
Partner - Contributor III

Hello,

Yes in the cloud environment I have the same issue, if I find a solution I'll share it with you !

SerhanKaraer
Creator III
Creator III

SET DateFormat='M/D/YY';

LOAD * INLINE [
Date, Qty
1/15/23, 0
1/14/23, 0
1/13/23, 10
1/12/23, 6
1/11/23, 3
1/10/23, 10
1/9/23, 2
1/8/23, 0
1/7/23, 5
1/6/23, 14
1/5/23, 26
1/4/23, 4
];

SerhanKaraer_0-1673891163349.pngSerhanKaraer_1-1673891182105.png

SerhanKaraer_2-1673891271723.png

Given a sort, Above function creates a range of rows specified as parameters, in this case 0 offset and 7 rows below.

Aggr(RangeSum(Above(Sum("Qty (A)"),0,7)),(Date,(NUMERIC,ASCENDING)))

You can get the same result by changing sort and direction for rows.

Aggr(RangeSum(Below(Sum("Qty (A)"),0,7)),(Date,(NUMERIC,DESCENDING)))

 You have to define it in a aggr function as when user changes the sort by pressing the title in the chart, your expression may execute wrong.