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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
QlikSenseLearner
Contributor
Contributor

How to write script to count the last 30 days for each date and load into temp table

 

I am developing app to show the count of service id's for last 30days for the each dates loaded. Please help to identify where I am going wrong.
 

 I am getting the same count for all the dates. But it should be different count for each date , it should represent the count of serviceid's  for past 30 days prior to each of the dates loaded through Variable. example:

date  30day volume
8/8/2022 11970
8/7/2022 12300
8/6/2022 12890
8/5/2022 11200
8/4/2022 12100

 

Please help me to find the solution. I am using the below script:

Let vMinDate = num(Date#('11/01/2021','MM/DD/YYYY')) ;
let vMaxDate= num(Date#(today(),'MM/DD/YYYY'));

For X=$(vMinDate) to $(vMaxDate)

Let Y= $(X)-30;

NoConcatenate
FinalCount:
Load Sum(ServiceIdCount) as 'TotalCount'
Resident XYZ
where Floor(Date)>=$(Y) and
Floor(Date) < $(X)
;

Let i = peek('TotalCount', 0 ,'FinalCount');

Temp:
Load
'$(X)' as 'Dte', '$(i)' as 'Cnt';


drop Table FinalCount;

Next X

drop table XYZ;

 

I am getting below result:

QlikSenseLearner_0-1660302816308.png

 

 

Labels (1)
2 Replies
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Hi,

 

I have tryed with this little example (last 2 days). I'm using intervalmatch for generating all 2 days interval and after than I sum the data.

 

Data:
Load
Date*1 as Date,
val
Inline [
Date, val
05/01/2022, 5
05/02/2022, 10
05/03/2022, 15
05/05/2022, 20
];

Left Join(Data)
IntervalMatch(Date)
Load
Date - 1 as Deb, //number of last days
Date*1 as DateFin
Resident Data
;

Load
DateFin,
Sum(val) as total
Resident Data
Group By
DateFin
;

Drop Table Data;

 

amartinez35_0-1660314364189.png

Aurélien

Help users find answers! Don't forget to mark a solution that worked for you!
QlikSenseLearner
Contributor
Contributor
Author

Thank you but I have large data so  it took 14 hrs to load the data and finally it failed.  It dint work for me.

I have one year data were each day the service id's will be created with the range of 4k-5k .  so for each day I have to calculate the  count of last 30 days service id's and insert the count to each date .