Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
what are loops in Qlik Sense and explain with example how it works?
⭐What Are Loops in Qlik Sense?
In the Qlik Sense Data Load Editor, a loop is a control-flow structure that repeats a section of script multiple times.
Qlik's scripting language supports three types of loops:
Loop Type | Purpose |
FOR … NEXT | Loop over numeric ranges, counters, lists, or field values |
DO … LOOP | Loop until a condition is met |
WHILE modifier | Add a repeat condition |
Why Use Loops? (Use Cases)
Loops are used in Qlik Sense for tasks that require repeated execution, such as:
Example: loading monthly CSV files named Sales_2024_01.csv, Sales_2024_02.csv, etc.
Example: iterating through years, months, days.
Loop until "nextPage" is empty.
Example: creating multiple calendars or loading repeated structures.
Example: iterating through table fields.
🟦WORKING EXAMPLE 1 — Single Loop
Scenario
You have 12 monthly sales files:
Sales_2024_01.csv
Sales_2024_02.csv
Sales_2024_12.csv
You want to load them all without writing 12 separate LOAD statements.
Script — Single FOR Loop
FOR i = 1 to 12
LET vMonth = Num(i, '00'); // Formats 1 → 01, 2 → 02 …
LET vFile = 'lib://Data/Sales_2024_' & vMonth & '.csv';
Sales:
LOAD *
FROM $(vFile)
(txt, utf8, embedded labels, delimiter is ',', msq);
NEXT i;
How it works
🟦WORKING EXAMPLE 2 — Nested Loops (Loop in a Loop)
Scenario
You have sales files for multiple years and months:
Sales_2023_01.csv … Sales_2023_12.csv
Sales_2024_01.csv … Sales_2024_12.csv
Sales_2025_01.csv … Sales_2025_12.csv
You want Qlik Sense to automatically load 3 years × 12 months = 36 files
Script — Loop Inside a Loop
FOR year = 2023 to 2025
FOR month = 1 to 12
LET vMonth = Num(month, '00');
LET vFile = 'lib://Data/Sales_' & year & '_' & vMonth & '.csv';
Sales:
LOAD
*,
$(year) AS Year,
$(vMonth) AS Month
FROM $(vFile)
(txt, utf8, embedded labels, delimiter is ',', msq);
NEXT month;
NEXT year;
How it works
Sales_2024_07.csv
Sales_2025_12.csv
🟦 Additional Loop Types in Qlik (for completeness)
LET i = 1;
DO
TRACE Loop iteration $(i);
LET i = i + 1;
LOOP UNTIL i > 5;
FOR EACH file IN FileList('lib://Data/*.csv')
LOAD * FROM $(file);
NEXT file;
🎯Summary
Loop Type | When to Use |
FOR … NEXT | Numeric ranges, counters, dates |
FOR EACH | Iterating over file lists or variables |
DO … LOOP UNTIL | Continue until a condition is met |
Nested Loops | Multi-dimension iteration (years × months etc.) |
Loops are extremely useful in dynamic data loading, eliminating repetitive scripts and making Qlik apps maintainable.
⭐What Are Loops in Qlik Sense?
In the Qlik Sense Data Load Editor, a loop is a control-flow structure that repeats a section of script multiple times.
Qlik's scripting language supports three types of loops:
Loop Type | Purpose |
FOR … NEXT | Loop over numeric ranges, counters, lists, or field values |
DO … LOOP | Loop until a condition is met |
WHILE modifier | Add a repeat condition |
Why Use Loops? (Use Cases)
Loops are used in Qlik Sense for tasks that require repeated execution, such as:
Example: loading monthly CSV files named Sales_2024_01.csv, Sales_2024_02.csv, etc.
Example: iterating through years, months, days.
Loop until "nextPage" is empty.
Example: creating multiple calendars or loading repeated structures.
Example: iterating through table fields.
🟦WORKING EXAMPLE 1 — Single Loop
Scenario
You have 12 monthly sales files:
Sales_2024_01.csv
Sales_2024_02.csv
Sales_2024_12.csv
You want to load them all without writing 12 separate LOAD statements.
Script — Single FOR Loop
FOR i = 1 to 12
LET vMonth = Num(i, '00'); // Formats 1 → 01, 2 → 02 …
LET vFile = 'lib://Data/Sales_2024_' & vMonth & '.csv';
Sales:
LOAD *
FROM $(vFile)
(txt, utf8, embedded labels, delimiter is ',', msq);
NEXT i;
How it works
🟦WORKING EXAMPLE 2 — Nested Loops (Loop in a Loop)
Scenario
You have sales files for multiple years and months:
Sales_2023_01.csv … Sales_2023_12.csv
Sales_2024_01.csv … Sales_2024_12.csv
Sales_2025_01.csv … Sales_2025_12.csv
You want Qlik Sense to automatically load 3 years × 12 months = 36 files
Script — Loop Inside a Loop
FOR year = 2023 to 2025
FOR month = 1 to 12
LET vMonth = Num(month, '00');
LET vFile = 'lib://Data/Sales_' & year & '_' & vMonth & '.csv';
Sales:
LOAD
*,
$(year) AS Year,
$(vMonth) AS Month
FROM $(vFile)
(txt, utf8, embedded labels, delimiter is ',', msq);
NEXT month;
NEXT year;
How it works
Sales_2024_07.csv
Sales_2025_12.csv
🟦 Additional Loop Types in Qlik (for completeness)
LET i = 1;
DO
TRACE Loop iteration $(i);
LET i = i + 1;
LOOP UNTIL i > 5;
FOR EACH file IN FileList('lib://Data/*.csv')
LOAD * FROM $(file);
NEXT file;
🎯Summary
Loop Type | When to Use |
FOR … NEXT | Numeric ranges, counters, dates |
FOR EACH | Iterating over file lists or variables |
DO … LOOP UNTIL | Continue until a condition is met |
Nested Loops | Multi-dimension iteration (years × months etc.) |
Loops are extremely useful in dynamic data loading, eliminating repetitive scripts and making Qlik apps maintainable.