Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
homersimpson
Not applicable

Questions about if and variables in scripts

Hi,

i want to run a script before the load script.

set vartest = "Hello";

set newTest = "";

if($(vartest) like 'Hello',

  // Then

  $(newTest) = $(vartest) & ' World!',

  // else

    $(newTest) = $(vartest) & ' how are you?'

);

tbl_name:

LOAD * Inline

[fieldname,

a

b

c

$(newTest) as newTest

];

The script editor shows error´s in the if statement. What´s wrong?

2017-01-25_14h28_20.jpg

Regards,

sam

3 Replies
sunny_talwar
Not applicable

Re: Questions about if and variables in scripts

May be this:

set vartest = "Hello";

set newTest = "";

if $(vartest) = 'Hello' THEN

  $(newTest) = $(vartest) & ' World!',

ELSE

  $(newTest) = $(vartest) & ' how are you?'

END IF;

tbl_name:

LOAD fieldname,

           $(newTest) as NewTest;

LOAD * Inline

[fieldname,

a

b

c

];

marcus_sommer
Not applicable

Re: Questions about if and variables in scripts

I think it should be more look like this:

set vartest = Hello;

set newTest = "";

if '$(vartest)' = 'Hello' THEN

  let newTest = '$(vartest)' & ' World!',

ELSE

  let newTest = '$(vartest)' & ' how are you?'

END IF;

tbl_name:

LOAD fieldname,

          '$(newTest)' as NewTest;

LOAD * Inline

[fieldname,

a

b

c

];

- Marcus

rahulpawarb
Not applicable

Re: Questions about if and variables in scripts

Hello Walter,

Hope you are doing well!

Please modify your script as below:

set vartest = "Hello"; 

LET newTest = if(vartest like "Hello", vartest & ' World!',  vartest & ' how are you?');

TRACE $(newTest);

Thank you!

Rahul