Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
mwallman
Contributor

Set a value for a variable and set the next value after each reload?

Hi all,

I would like to create a variable in the script that holds a certain value that updates every time there is a reload.

The value should iterate over from 1993 to 1998.

So for example it is 1993

After I reload it should be 1994

Then the next reload it should be 1995

...

Until 1998, after 1998 it should again hold the value of 1993.

Here is the basic of what I want to do:

SET vYear = <value of year based on above>;

LOAD

$(vYear) as CurrentYear,

<fields>

From file.txt;

How is it possible to create a variable like this please?

7 Replies

Re: Set a value for a variable and set the next value after each reload?

May be this

LET vYear = If(vYear = 1998, 1993, $(vYear) + 1);

mwallman
Contributor

Re: Set a value for a variable and set the next value after each reload?

Hi Sunny,

It's a good idea, however I get 1, 2, 3 as results and not 1993, 1994 etc. Any ideas why?

Re: Set a value for a variable and set the next value after each reload?

I am a little confused, are you trying to loop through these values during a single reload? or are you trying to increment by 1 every time you reload?

MVP
MVP

Re: Set a value for a variable and set the next value after each reload?

Have you initialized your vYear variable once to 1993?

mwallman
Contributor

Re: Set a value for a variable and set the next value after each reload?

Hi Sunny,

I am trying to loop through them. So initial value could be 1993, then after the next reload it would be 1994, then next reload it would be 1995 etc. Until 1998, after this it loops through again and start at 1993.

Re: Set a value for a variable and set the next value after each reload?

Try this may be:

LET vYear = If(vYear <> 1998, $(vYear) + 1, 1993);

or

LET vYear = If(Len(Trim(vYear)) = 0, 1993, If(vYear = 1998, 1993, $(vYear) + 1);

alexpanjhc
Valued Contributor

Re: Set a value for a variable and set the next value after each reload?

try this?

If $(vFirst)=0 then

LET vYear=1992;

end if;

LET vYear = If(vYear = 1998, 1993, $(vYear) + 1);// i copied sunny's idea here...

set vFirst=1;

Community Browser