5 Replies Latest reply: Jan 29, 2015 12:41 PM by Peter Cammaert RSS

    If..then..elseif..endif

    frank volpe

      I'm trying to get this compound if to work but having problems with the syntax.  any ideas?  Thanks.

       

      If ([Bill To Address] = 3670 or 5970,
      if (PDorSP = 'PD', 'MY',
      if (PDorSP = 'SP',
      if (SDSRP2 = 'PEA' or 'SOY', 'MY',
      if (SDSRP2 <> 'PEA' and 'SOY', 'LI'))))),
      //*
      else if (PDorSP = 'PD', PTSM,
      If(PDorSP = 'SP', STSM,
      If(PDorSP = 'FB', 'PB',
      If(
      [Line Type] = 'MP' or [Line Type] = 'FP',PTSM,
      If(
      [Line Type] = 'MS' or [Line Type] = 'FS',STSM,
      if (
      [Line Type] = 'M' or [Line Type] = 'F' or [Line Type] = 'Z' or [Line Type] = 'Y',
      if (SDSRP1 = 'PD', PTSM,
      if (SDSRP1 = 'SP', STSM,
      if (SDSRP1 = 'FB' or SDSRP1 = 'PKG' or SDSRP1 = 'CMF' or SDSRP1 = 'RAW' or SDSRP1 = 'OTH', 'PB',)))))))))
      end if as
      [Territory Manager],


        • Re: If..then..elseif..endif
          Peter Cammaert

          Change all conditions like

           

          [Bill To Address] = 3670 or 5970


          that don't work in QlikView, into


          ([Bill To Address] = 3670) or ([Bill To Address] = 5970)


          Use lots of indentation and parentheses to separate the different clauses in your statement.


          Best, Peter

          • Re: If..then..elseif..endif
            Joseph Simmons

            Hi Frank,

             

            the If syntax within the QV load script isn't in that format, needs to be like the below

            IF(Evaluation,[True Condition],[False Condition])

            You can't you elseif like that when creating a field.

            Also using the Or/And like that will not give the required result, you need to specify the OR/AND separately

            i.e

            If([Bill to Address]=3670 OR [Bill to Address]=5970, [True], [False})

             

            hope that helps

            Joe

              • Re: If..then..elseif..endif
                frank volpe

                Thank Peter & Joe,

                 

                I made the correction you suggested, however I'm still receiving an error when the script runs.  I'm not sure that the else is working properly.  As you will notice all the "if" after the else are not in blue the way they should be.

                 

                If ([Bill To Address] = 3670 or [Bill To Address] = 5970,
                if (PDorSP = 'PD', 'MY',
                if (PDorSP = 'SP',
                if (SDSRP2 = 'PEA' or 'SOY', 'MY',
                if (SDSRP2 <> 'PEA' or SDSRP2 <> 'SOY', 'LI'))))),
                //*
                else if (PDorSP = 'PD', PTSM,
                If(PDorSP = 'SP', STSM,
                If(PDorSP = 'FB', 'PB',
                If(
                [Line Type] = 'MP' or [Line Type] = 'FP',PTSM,
                If(
                [Line Type] = 'MS' or [Line Type] = 'FS',STSM,
                if (
                [Line Type] = 'M' or [Line Type] = 'F' or [Line Type] = 'Z' or [Line Type] = 'Y',
                if (SDSRP1 = 'PD', PTSM,
                if (SDSRP1 = 'SP', STSM,
                if (SDSRP1 = 'FB' or SDSRP1 = 'PKG' or SDSRP1 = 'CMF' or SDSRP1 = 'RAW' or SDSRP1 = 'OTH', 'PB',)))))))))
                end if as
                [Territory Manager],