8 Replies Latest reply: Dec 5, 2016 2:22 AM by Adam Davies RSS

    [ASK] if-else looping load with multiple condition

    Rendi Yanuar

      Dear Qlik Master,

       

      I have a user with huge data.

      I have 1 transaction that i need to load partially every year.

      And loaded before current year data only need to load 1 time.

       

      So i create a looping load with multiple condition, and my script is below  :

      Load Script

      FOR nrow = 0 TO 2

      LET vYear = year(today())-$(nrow);

       

      set vTable = F_REVBYTYPE_$(vYear);

      set QVDFILE_max = $(vTable).qvd;

       

      IF '$(vYear)'=year(today()) THEN

        $(vTable):

      sql select *

      from abc

      where abc.date=$(vYear);

      STORE * from $(vTable) into $(vTable).qvd (qvd);

      DROP TABLE $(vTable);

       

      ELSEIF '$(vYear)'<>year(today()) and FileSize('$(QVDFILE_max)') = 0 THEN

      sql select *

      from abc

      where abc.date=$(vYear);

      STORE * from $(vTable) into $(vTable).qvd (qvd);

      DROP TABLE $(vTable);

       

      ENDIF;

       

      NEXT;

       

      But i got a problem, my load script never get to elseif condition.

      Is there anything wrong with my script?

       

      Because when i try with only if-else, it's going well.

       

      Thank You,

      Best Regards,

        • Re: [ASK] if-else looping load with multiple condition
          Adam Davies

          WHy do you need the elseif?

          Surely you just need ELSE ?

           

          I've not tried to use ELSEIF as a function (I nest IFs as below) so i could be wrong but is it missing an ENDIF and maybe it requires an ELSE to work?

           

          I personally would use this and never have an issue:

           

          IF <condition> THEN

              statement1

          ELSE

              IF <condition2> THEN

                statement2

              ELSE

                    statement3

               ENDIF

          ENDIF

            • Re: [ASK] if-else looping load with multiple condition
              Rendi Yanuar

              Hi Adam,

               

              thx for the quick response.

               

              I've tried it but it won't work, only ran the first if load script.

              Script is below :

              FOR nrow = 0 TO 2

              LET vYear = year(today())-$(nrow);

               

              set vTable = F_REVBYTYPE_$(vYear);

              set QVDFILE_max = $(vTable).qvd;

               

              IF '$(vYear)'= year(today()) then

                $(vTable):

                LOAD * INLINE [

                YEAR

                '$(vYear)'

                ];

                STORE * from $(vTable) into $(vTable).qvd (qvd);

                DROP TABLE $(vTable);

               

              ELSE

                IF FileSize('$(QVDFILE_max)') = 0 then

                $(vTable):

                LOAD * INLINE [

                YEAR

                '$(vYear)'

                ];

                STORE * from $(vTable) into $(vTable).qvd (qvd);

                DROP TABLE $(vTable);

               

                ELSE

                $(vTable):

                LOAD * INLINE [

                BEFYEARDONE

                1

                ];

               

                ENDIF;

              ENDIF;

              NEXT;