Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Subbug_31
Contributor
Contributor

Data Accumulation in script

Hi,

I have a data like below from source

 

126-Aug
226-Aug
326-Aug
427-Aug
527-Aug
627-Aug
727-Aug
827-Aug
928-Aug
10

28-Aug

 

I would like to accumulate the data and create like below in Qlik script.

 

26-Aug1
26-Aug2
26-Aug3
27-Aug1
27-Aug2
27-Aug3
27-Aug4
27-Aug5
27-Aug6
27-Aug7
27-Aug8
28-Aug1
28-Aug2
28-Aug3
28-Aug4
28-Aug5
28-Aug6
28-Aug7
28-Aug8
28-Aug9
28-Aug10

 

Can you please help me out.

 

Regards

Subbu

2 Replies
Taoufiq_Zarra

@Subbug_31 

One solutio:

Input:
load * inline [
    ID, Date
    1, 26-Aug
    2, 26-Aug
    3, 26-Aug
    4, 27-Aug
    5, 27-Aug
    6, 27-Aug
    7, 27-Aug
    8, 27-Aug
    9, 28-Aug
    10, 28-Aug
];
left join load Date,Max(ID) as MaxTmp resident Input group by Date;

Tmp:
load distinct MaxTmp as Mtmp,Date as Datetmp resident Input;

Final:

LOAD 1 as Tmp

autogenerate 1;

LET NumRows=NoOfRows('Tmp');
	
	FOR i=0 to $(NumRows)-1

	Join(Final)
	
	LET varMax=Peek('Mtmp',$(i),'Tmp');
    LET vdate=peek('Datetmp',$(i),'Tmp');
	Let varMin = 1;
	
	LOAD $(varMin) + Iterno()-1 As IDtmp,'$(vdate)' as Date
	
	AutoGenerate 1 While $(varMin) + IterNo() -1 <= $(varMax);
	
	NEXT i
drop tables Tmp,Input;
DROP Field Tmp;

 

output:

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Kushal_Chawda

@Subbug_31  try below just to avoid complex for loops and keep script cleaner

Data:
load * inline [
    ID, Date
    1, 26-Aug
    2, 26-Aug
    3, 26-Aug
    4, 27-Aug
    5, 27-Aug
    6, 27-Aug
    7, 27-Aug
    8, 27-Aug
    9, 28-Aug
    10, 28-Aug
];

Left Join(Data)
LOAD Date,max(ID) as To_Count,
     1 as From_Count
Resident Data
Group by Date;

Final:
LOAD Distinct
     Date,
     From_Count+IterNo()-1 as Counter
Resident Data
while From_Count+IterNo()-1<=To_Count;

DROP Table Data;

 

Annotation 2020-09-10 114920.png