8 Replies Latest reply: Apr 29, 2011 8:58 AM by Sravan Puppala

# Define Variable based on week

Hi I have this problem with the loop.

I am looping with the weeks and my loop is for 201115[vCurrweek] to 201118(\$(vCurWeek)+3)

If the "week" Field in Temp_table is same as \$(Vcurrweek) I want to save the stock as variable Stock.

I dont know how to write this

I tried

Let Stock = Peek('WeeklyStock');

But it does not give me the Stockvalue when week is 'i'

`SET CV= '0'; For i= \$(vCurWeek) to (\$(vCurWeek)+3) Temp_Table: Load SID_0CALWEEK as Week, Material as Material, SID_CMATLOC as [Location], [Weekly Material Stock] as WeeklyStock, [Weekly Material Demand] as WeeklyDemand Resident FactTable ; if(\$(i) = Fieldvalue(Week)) then Let Stock = Fieldvalue('WeeklyStock'); Endif If(\$(Stock) <= 0) then \$(CV) else exit script() End If........`

Thanks

sravan

• ###### Define Variable based on week

No Ideas???

• ###### Define Variable based on week

`if(\$(i) = Fieldvalue(Week)) then Let Stock = Fieldvalue('WeeklyStock'); EndifDoes the script go inside the if-case? You can use TRACE to check if the if-condition was ok... if(\$(i) = Fieldvalue(Week)) thenTRACE IS OK; Let Stock = Fieldvalue('WeeklyStock'); EndifYou are using the FieldValue in two different ways. On the first line of your code, try: Fieldvalue('Week')Is week a numeric field to be compared with \$i)?Rgds,`
• ###### Define Variable based on week

edit: Too big and confusing

• ###### Define Variable based on week

I think I am doing some silly Mistake...

when I comment the whole "j" loop, "i" loop works correctly and also Stock variable is correct.

If I test for one "i" value, the whole "j" loop and "i" loop works good.

I wonder why after one i value and loop of J values it does not work for second i value in the loop!

• ###### Define Variable based on week

Removed too big and confusing

• ###### Define Variable based on week

`Trace \$(Stock);try to use trace \$(i); and trace \$(j) and trace \$(vFieldValue2); and trace \$(vFieldValue_2) to gather more information about what is going on`
• ###### Define Variable based on week

Edit

Too complicated hence added a simple example later

• ###### Define Variable based on week

Hey Erich,

I finally got it work but still have 2 questions. May be you can help me. The problem was between the concatenate and Peek expressions. Somehow peek does not work with concatenate for the tables t1 and t2 (I replaced with Noconcatenate and it works but generates lot of t tables)

When I keep noconcatenate load for t1 and t2 tables, it works but I get a lot of "t" tables. I want to do this calculation of cover for a lot of Materials by looping with each material and I see the problem that my Datamodel will be full of unlimited "t" tables.

First Question:

I need to get the CV values( defined as CV variable) in this manner within the table.

From the above table, the calculation which I made in Qlikview is based on this WordDocument

I get the values CV in my script as a Variable and I need to somehow save them as Field "Cover" in the table "Temp_Table". How??

Second Question:

How to get the t tables reduced in the script? I actually needed only Coverage values and hence these loops. Otherwise I dont need the t tables.

I am attaching a simple example for the figure above showing the values.

Hope you can help me.

Thanks and regards

Sravan