Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
soha1902
Creator
Creator

Previous

Hi All,

I have following Data:

Load * Inline [
Date,Sales
12/12/2014,50
01/01/2015,100
01/02/2015,200
01/03/2015,300
01/04/2015,500
01/05/2015,600 ]
;

Tab1:
Load
Date as Date,
Sales as Sales,
Previous(Previous(Sales)) as PreSales
Resident Tab;
Drop Table Tab;

As of now in "Presales" column I am getting values of last 2 days but in future this value will be change for last 5 or some other number.

So please let me the dynamic way which I can use in place of previous.

17 Replies
sunny_talwar

May be use Peek instead of Previous where you can specify how much back you want to go.

sunny_talwar

Try this script:

Tab:

Load * Inline [

Date, Sales

12/12/2014, 50

01/01/2015, 100

01/02/2015, 200

01/03/2015, 300

01/04/2015, 500

01/05/2015, 600

];

LET vBack = -3;

Tab1:

Load Date,

  Sales,

  Peek(Sales, $(vBack)) as PreSales

Resident Tab;

Drop Table Tab;

Here you can set value for vBack before running the script.

Not applicable

Hi soha1902

you can use the code given below for the sum of previous two days.And let me know for more information

Tab1:

Load

Date as Date,

Sales as Sales,

Rangesum(Peek(Sales,-2),Previous(Sales)) as PreSales

Resident Tab;

Drop Table Tab;

soha1902
Creator
Creator
Author

Hi Sunny,

Thanks for you reply. your solution is correct but my requirement is little bit change. Hope you dont mind.

Now I want to sum of all sales for all previous date

For example

if I select 01/05/2015 then Presales would be 1000.

sunny_talwar

This can be done more easily in front end? Are you looking specifically for a back end solution?

Not applicable

hi soha1902‌,

you can use the below code for the sum of all the previous days on script.

Tab1:

Load

Date as Date,

Sales as Sales,

RangeSum(Previous(Sales),Peek(Sales,0))  as SumofallPreviousDays

Resident Tab;

Drop Table Tab;

soha1902
Creator
Creator
Author

Yes Back End Solution only

sunny_talwar

Do you know how much back you would be adding? Is it going to be dynamic?

soha1902
Creator
Creator
Author

As of now 4 only