# App Development

Announcements
Qlik Cloud Maintenance is scheduled between March 27-30. Visit Qlik Cloud Status page for more details.
cancel
Showing results for
Did you mean:
Creator

## Double Loop

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

1 Solution

Accepted Solutions
Partner - Master III

yes it is possible

Foe Ex;

For i = 0 to 10

For j = 0 to 5

Some code

Next

Next

9 Replies
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

Partner - Master III

yes it is possible

Foe Ex;

For i = 0 to 10

For j = 0 to 5

Some code

Next

Next

Creator
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'

MVP

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

MVP

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

Creator
Author

Set ErrorMode = 0;

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

NoConcatenate
MaxMonthYear:
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)
*
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)
*
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.

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."