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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Increment count using loop

Hi Guys ,

i have very urgent requirement on looping concept .

Below is my scenario .

Everytime Year column should concatenate with P1 to P13 .

So instead of writing it 13 times can i have in loop .

Please suggest me  .

Thanks in advance

load distinct

EmpKey ,

AutonumberHash128(DeptKey) as DepKey,

Year&'P01' As YearPeriod

Resident Emp ;

concatnate

load distinct

EmpKey ,

AutonumberHash128(DeptKey) as DepKey,

Year&'P02' As YearPeriod

Resident Emp ;

concatnate

load distinct

EmpKey ,

AutonumberHash128(DeptKey) as DepKey,

Year&'P03' As YearPeriod

Resident Emp ;

6 Replies
sunny_talwar

May be like this:

Table:

LOAD 0 as Dummy

AutoGenerate 0;

For i = 1 to 13

     Concatenate (Table)

     LOAD DISTINCT

     EmpKey,

     AutonumberHash128(DeptKey) as DepKey,

     Year&'P'&Num($(i), '00') As YearPeriod

     Resident Emp ;

NEXT

DROP Field Dummy;

johnw
Champion III
Champion III

How about this?

LOAD DISTINCT
EmpKey
,autonumberhash128(DeptKey) as DepKey
,Year&'P'&num(iterno(),'00') as YearPeriod
RESIDENT Emp
WHILE iterno()<=13
;

johnw
Champion III
Champion III

Or this?

LOAD DISTINCT
EmpKey
,autonumberhash128(DeptKey) as DepKey
,Year&'P'&subfield('01,02,03,04,05,06,07,08,09,10,11,12,13',',') as YearPeriod
RESIDENT Emp
;

Perhaps silly when it's just 01 - 13, but useful if it was some other sort of distinct values.

Not applicable
Author

John, I guess IterNo() is more optimal method than subfield function method.

johnw
Champion III
Champion III

I would guess so as well. The other method would be more if we were building values like 2016 Apple, 2016 Grape, and 2016 Banana.

Not applicable
Author

Thank you John , its working