14 Replies Latest reply: Jan 15, 2013 5:15 AM by Dong Jiang RSS

    nested if then control statement

      Hello everyone,

       

      I want to nest the if...then statement like

      if ... then

           do something

           if... then

                do something

           endif

      else

           do something

      endif

       

      The problem is: there are two endifs and qlikview stops at the first one and doesn't go futher. Does anyone have a solution for this issue?

       

      Many thanks in advance

        • Re: nested if then control statement
          Adam Wilson

          is the first endif needed?

           

           

          if ... then

               do something

               if... then

                    do something

          else

               do something

          endif

          • Re: nested if then control statement
            Nagaian Krishnamoorthy

            Here is an extract from Qlikview Reference Manual. If you follow the syntax, it will work.

             

            The syntax is:

            if condition then

            [ statements ]

            { elseif condition then

            [ statements ] }

            [ else

            [ statements ] ]

            end if

            Where:

            condition is a logical expression which can be evaluated as true or false.

            statements is any group of one or more QlikView script statements.

            Since the if..then statement is a control statement and as such is ended with either a semicolon or end-of-line,

            each of its four possible clauses (if..then, elseif..then, else and end if) must not cross a line boundary.

            • Re: nested if then control statement

              For the syntax outside of the load statement it is just:

               

              IF  Criteria A  THEN

               

                   IF  Criteria 1  THEN

                         Set vSomeVariable = 'A1';

               

                   ELSEIF  Criteria 2  THEN

                         Set vSomeVariable = 'A2';

               

                   ELSE 

                         Set vSomeVariable = 'A#';

               

                   END IF   

               

               

              ELSEIF  CriteriaB  THEN

               

                   IF  Criteria 1  THEN

                         Set vSomeVariable = 'B1';

               

                   ELSEIF  Criteria 2  THEN

                         Set vSomeVariable = 'B2';

               

                   ELSE

                         Set vSomeVariable = 'B#';

               

                   END IF 

               

              ELSE

               

                   Set vSomeVariable = 'XX';

               

              END IF

               

               

              As flipside said, you have probably missed a semicolon or something like that.

                • Re: nested if then control statement

                  Do I have to use the complete clause? I tried with the following syntax:

                   

                  IF  Criteria A  THEN

                   

                       IF  Criteria 1  THEN

                             Set vSomeVariable = 'A1';

                   

                       ELSEIF  Criteria 2  THEN

                             Set vSomeVariable = 'A2';

                   

                       ELSE 

                            

                       END IF   

                   

                   

                  ELSEIF  CriteriaB  THEN

                   

                       IF  Criteria I  THEN

                             Set vSomeVariable = 'B1';

                   

                       ELSEIF  Criteria II  THEN

                             Set vSomeVariable = 'B2';

                   

                       ELSE

                          

                       END IF 

                   

                  ELSE

                   

                  END IF

                   

                  I have only two criteria in each clause, so it's empty by else. The criteria A is not fulfilled, instead of comparing criteria B, it goes to criteria 2. I just don't understand why.