Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

reivax31
Not applicable

If , Then, Else ... In LOAD

Hi Qlikers,

I'm wondering if it il possible to use IF, THEN, ELSE in LOAD.

This is what I’m trying to do:

LOAD

if "Test" = 'empty' then

  if "Test2" = 'empty' then

  'Empty'

  Else

  'New'

  End if

Else

'OLD'

End if AS "Test3"

FROM ...

Is there something wrong with my syntax, or the only possible way iln LOAD  is to do

LOAD

If("Test"= 'empty', if (“Test2”=’empty’, ’empty’,’New’),’OLD’) as "Test3"

FROM ...

Thanks for your help

Tags (2)
11 Replies
stalwar1
Not applicable

Re: If , Then, Else ... In LOAD

LOAD

If("Test"= 'empty', if (“Test2”=’empty’, ’empty’,’New’),’OLD’) as "Test3"

FROM ...

This looks right not me. Are you running into issues?

Not applicable

Re: If , Then, Else ... In LOAD

Is Test a field name? If yes, then remove the quotes. Right now it is comparing Test and empty as a string and hence the error. May be.

reivax31
Not applicable

Re: If , Then, Else ... In LOAD

Hi Sunny,

Yes the following syntax is working:

If("Test"= 'empty', if (“Test2”=’empty’, ’empty’,’New’),’OLD’) as "Test3"

I want to know if the other syntax can work also

reivax31
Not applicable

Re: If , Then, Else ... In LOAD

Hi Vishal,

I tried but it is not working. I think that Inside a LOAD the IF, THEN, ELSE doesn't work. So I guess I will have to write every thing like:

If("Test"= 'empty', if (“Test2”=’empty’, ’empty’,’New’),’OLD’) as "Test3"

stalwar1
Not applicable

Re: If , Then, Else ... In LOAD

AFAIK you cannot use the other syntax. But why are you trying to use if the second one works? Any specific reasons?

Not applicable

Re: If , Then, Else ... In LOAD

LOAD

If("Test"= 'empty', if (“Test2”=’empty’, ’empty’,’New’),’OLD’) as "Test3"

FROM ...

petter
Not applicable

Re: If , Then, Else ... In LOAD

You can always format the load script variant by having it on separate lines and indenting it:

The // comments are optional - but to make the similarity with the former syntax clearer...

LOAD

      ....

      If ( "Test" = 'empty ,  //THEN

            If ( "Test2" = 'empty' ,  //THEN

                    'empty'

            , //ELSE

                    'New'

            )//ENDIF

        ,//ELSE

          'OLD'

        )//ENDIF

            as "Test3",

      ....

reivax31
Not applicable

Re: If , Then, Else ... In LOAD

It was just because the syntax with IF, THEN, ELSE, is easier to understand. But we will manage it with the syntax that works

reivax31
Not applicable

Re: If , Then, Else ... In LOAD

Thanks for this trick !