Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
WEBINAR June 25, 2025: Build on Apache Iceberg with Qlik Open Lakehouse - REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
Newhaven
Contributor III
Contributor III

variabel let = peek not worked

Hello!

 

I have this example script for a try:

-------------

Data:
LOAD * INLINE [
Week, Sum
1, 20
2, 20
3, 40
4, 10
5, 30
6, 70
7, 40
8, 30
9, 10
10, 25
11, 10
12, 13
13, 20
14, 10
15, 15
];


MapSum:
Mapping load
Week, Sum Resident Data;


Multipl = 3;


For i = 1 to 15

Calculate:
Load *,
round(SumNew / Multipl, 1) as MultiplFinal;
Load *,
ApplyMap('MapSum', Key, 0) as SumNew;
Load *,
round(Sum / Multipl, 1) as Key;


NoConcatenate Load *,
$(Multipl) as Multipl
Resident Data where Week = $(i);


Let Multipl = Peek('MultiplFinal', 0, 'Calculate');
Next i;


drop table Data;

----------

Let Multipl = Peek('MultiplFinal', 0, 'Calculate'); doesn't work.

For week 2 new Multipl  = 13 is correct.

By for the next weeks it doesn't work - there is always the value 13 as Multipl?

Thx.

 

Labels (3)
2 Solutions

Accepted Solutions
BPiotrowski
Partner - Contributor III
Partner - Contributor III

Hi @Newhaven 

Try this:

Calculate:
Load *,
round(SumNew / Multipl, 1) as MultiplFinal;
Load *,
ApplyMap('MapSum', Key, $(i)) as SumNew;
Load *,
round(Sum / Multipl, 1) as Key;


NoConcatenate Load *,
$(Multipl) as Multipl
Resident Data where Week = $(i);


Let Multipl = Peek('MultiplFinal', $(i)-1, 'Calculate');

The problem is you allways get row nr. 0 in your peek 🙂

View solution in original post

BPiotrowski
Partner - Contributor III
Partner - Contributor III

HI,

So the thing is your table row count starts from 0 and your iterator i starts from 2

So when you give $(i)-1 in peek you have 2-1=1

Peek RowNo starts from 0

so you need:

Let DeliveryWeek = Peek('FinalDeliveryWeek', $(i)-2, 'calculation');

Wish this helps 🙂

View solution in original post

9 Replies
marcus_sommer

Just integrate the intended variable-result directly in the load and don't drop the table afterwards to be able to look on the results. For the shown example it seems not necessary but often it's also useful to add recno(), rowno() and each iteration-counter like iterno() respectively here $(i) within the load to track the complete evolution from the raw-data to the final output.

Beside this I could imagine that 0 isn't the wanted row-index else it may -1, like:

Peek('MultiplFinal', -1, 'Calculate') 

BPiotrowski
Partner - Contributor III
Partner - Contributor III

Hi @Newhaven 

Try this:

Calculate:
Load *,
round(SumNew / Multipl, 1) as MultiplFinal;
Load *,
ApplyMap('MapSum', Key, $(i)) as SumNew;
Load *,
round(Sum / Multipl, 1) as Key;


NoConcatenate Load *,
$(Multipl) as Multipl
Resident Data where Week = $(i);


Let Multipl = Peek('MultiplFinal', $(i)-1, 'Calculate');

The problem is you allways get row nr. 0 in your peek 🙂

Newhaven
Contributor III
Contributor III
Author

Perfekt Thx.:-)

Newhaven
Contributor III
Contributor III
Author

Okay, next question. I tried inserting the example into a script, but I'm getting a syntax error:

 


quantity:
LOAD
week,
num#(order, '0,00') AS order,
num#(production, '0,00') AS production
INLINE [
week, order, production
1, "121,41", "0,00"
2, "202,34", "487,66"
3, "202,34", "331,46"
4, "202,34", "321,55"
5, "202,34", "316,54"
6, "394,38", "298,19"
7, "394,38", "254,87"
8, "394,38", "0,00"
9, "394,38", "511,92"
];

 

MapCapacityProduction:
mapping LOAD week, production Resident quantity;

 

// Set delivery week
DeliveryWeek = 6;

 

for i = 2 to 5



calculation:
//Final DeliveryWeek
Load *,
if(DeliveryWeekChange > 0, DeliveryWeekChange,
if(DeliveryWeek > 0, DeliveryWeek, 0 )) as FinalDeliveryWeek;


//Change DeliveryWeek
Load *,
if(CapacityProductionDay * 2 > Delta, DeliveryWeek + 1, 0) as DeliveryWeekChange,
if(CapacityProductionDay * 2 > Delta, DeliveryWeek + 1, 0)-1 as ProductionWeekChange, //always DeliveryWeek -1
ApplyMap('MapCapacityProduction', (if(CapacityProductionDay * 2 > Delta, DeliveryWeek + 1, 0)-1), $(i)) as CapacityProductionWeekChange1;
Load *,
CapacityProduction - order as Delta,
round(CapacityProduction / 5, 0.01) as CapacityProductionDay;
NoConcatenate load *,
$(DeliveryWeek) as DeliveryWeek,
$(DeliveryWeek) - 1 as ProductionWeek,
ApplyMap('MapCapacityProduction',($(DeliveryWeek) - 1), $(i)) as CapacityProduction //always DeliveryWeek -1
Resident quantity where week = $(i);


Let DeliveryWeek = Peek('FinalDeliveryWeek', $(i)-1, 'calculation');

Next i;

drop Table quantity;

 

Thx 🙂

marcus_sommer

Just perform your script step by step - loop without the loads, then the lowest one, only one iteration and maybe even more granular by commenting single lines or sub-parts of them. It shouldn't take very long until you detects the part which breaks the execution.

Newhaven
Contributor III
Contributor III
Author

Tried this. Error is in the let command:

 

Let DeliveryWeek = Peek('FinalDeliveryWeek', $(i)-1, 'calculation');

 

Result: DeliveryWeek <NULL>

 

Don't knwo why. Because for i = 2 there is he correct result FinalDeliveryWeek = 7

 

 

marcus_sommer

DeliveryWeek is the name of your variable and a field - and probably causing a conflict. You may add a prefix to your variable to avoid a mismatch, maybe: vDeliveryWeek

BPiotrowski
Partner - Contributor III
Partner - Contributor III

HI,

So the thing is your table row count starts from 0 and your iterator i starts from 2

So when you give $(i)-1 in peek you have 2-1=1

Peek RowNo starts from 0

so you need:

Let DeliveryWeek = Peek('FinalDeliveryWeek', $(i)-2, 'calculation');

Wish this helps 🙂

Newhaven
Contributor III
Contributor III
Author

Perfekt. What a mistake 🙂 Thx!!