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: 
Anonymous
Not applicable

Double Loop

Is it possible to do a double loop in qlik? one inside the other?

1 Solution

Accepted Solutions
shraddha_g
Partner - Master III
Partner - Master III

yes it is possible

Foe Ex;

For i = 0 to 10

      For j = 0 to 5

            Some code

Next

Next

View solution in original post

9 Replies
swuehl
MVP
MVP

You are talking about e.g. a FOR ... NEXT loop in the script?

An example for a nested loop can be found here:

For each..next ‒ Qlik Sense

shraddha_g
Partner - Master III
Partner - Master III

yes it is possible

Foe Ex;

For i = 0 to 10

      For j = 0 to 5

            Some code

Next

Next

Anonymous
Not applicable
Author

I'm trying to do the loop to get the name of tabs in a sheet so I can load all of the tabs in an excel sheet and the way the titles for the tabs are set up is 'MMM-YYYY'

swuehl
MVP
MVP

Ok, so how does your current code look like? Do you also have a sample Excel file to work with?

its_anandrjs

Sheet names are in this formats MMM-YYYY is so it comes same name when you apply loop on the sheets.

Anonymous
Not applicable
Author


Set ErrorMode = 0;

NoConcatenate
TableName:
Load
    *
From x
(ooxml, embedded labels, table is Current)
Where Num(MonthYear)<>Null();

NoConcatenate
MaxMonthYear:
Load
Max(Date) As TNMaxMY
Resident TableName;

Let vTNMaxMY=Peek('TNMaxMY');

Let vTNMaxMon=Num(Month($(vTNMaxMY)));

Let vTNMaxYear=Num(Year($(vTNMaxMY)));

Let vTNMonPrev=$(vTNMaxMon)-1;


// First for loop
For Year=Start Year to $(vTNMaxYear);

Let vYear=$(Year);

//For Loop

    For num=1 to 12
   
Let vMY=Date(MakeDate($(vYear),$(num)),'MMM-YYYY');

    Concatenate(TableName)
    Load
       *
    From x
    (ooxml, embedded labels, table is [$(vMY)])
    Where Num(MonthYear)<>Null();

Next

Next

Drop Table MaxMonthYear;


If ScriptErrorCount > 0 then

End IF;

// ErrorMode set back to 1
Set ErrorMode = 1;

// Load DataRefresh.QVD to have previously loaded data and used Exit Script as part of error handling

Concatenate(TableName)
Load
    *
From x(qvd)
Where [TableName]='TableName' and Not Exists(Key);

This ended up to be the code that worked for me to get all the tabs in the excel file for whatever year and month and to be able to have missing months.

swuehl
MVP
MVP

"This ended up to be the code that worked for me to get all the tabs in the excel file for whatever year and month and to be able to have missing months."


Hm, so there is no open issue? Then please close the thread by selecting 'assumed answered'.

Anonymous
Not applicable
Author

There was this thread helped I will close it

swuehl
MVP
MVP

Great, thank you!