Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

kellymcgrady
Contributor

Double Loop

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

Tags (2)
1 Solution

Accepted Solutions
shraddha_g
Honored Contributor III

Re: Double Loop

yes it is possible

Foe Ex;

For i = 0 to 10

      For j = 0 to 5

            Some code

Next

Next

9 Replies
MVP
MVP

Re: Double Loop

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
Honored Contributor III

Re: Double Loop

yes it is possible

Foe Ex;

For i = 0 to 10

      For j = 0 to 5

            Some code

Next

Next

kellymcgrady
Contributor

Re: Double Loop

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
MVP

Re: Double Loop

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

Re: Double Loop

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

kellymcgrady
Contributor

Re: Double Loop


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.

MVP
MVP

Re: Double Loop

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

kellymcgrady
Contributor

Re: Double Loop

There was this thread helped I will close it

MVP
MVP

Re: Double Loop

Great, thank you!