Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
reivax31
Partner - Creator III
Partner - Creator III

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

11 Replies
sunny_talwar

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

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
Partner - Creator III
Partner - Creator III
Author

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
Partner - Creator III
Partner - Creator III
Author

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"

sunny_talwar

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

Not applicable

LOAD

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

FROM ...

petter
Partner - Champion III
Partner - Champion III

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
Partner - Creator III
Partner - Creator III
Author

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
Partner - Creator III
Partner - Creator III
Author

Thanks for this trick !