2 Replies Latest reply: Jul 23, 2018 11:30 AM by Ali Ahmad RSS

    Help with If Statement

    Javiera Rojas

      Hello there,

      I have and cvs file with 10 columns, everytime I try an If statement it gives me an error

      Idk what Im doing wrong

      LOAD [ID orden] as [ID Orden], 
           [ID cliente] as [ID Cliente], 
           [ID vendedor] as [ID Vendedor], 
           [Fecha Pedido], 
           Margen, 
           Descuento, 
           [ID Producto] as [ID Producto], 
           Cantidad, 
           [Precio Unitario], 
           Venta
           If(Venta =200 and Venta= 400 and Venta < 600, '400-600', 
           If(Venta>=600 and Venta < 800, '600-800', '800+')))) as Range_Venta
      
      FROM......
      .........
      

      Hope you can help, and thanks

        • Re: Help with If Statement
          m w

          If Venta can't be <200, this works. Otherwise need another if 

           

          If(Venta >=400 and Venta < 600 , '400-600',

               If(Venta>=600 and Venta < 800, '600-800', '800+')) as Range_Venta

          • Re: Help with If Statement
            Ali Ahmad

            Hi,

             

            Don't you want anything to cover the 0-400 range?

             

            You can put this in a QlikView Script and see how this one works:

             

            Temp:

            LOAD * INLINE [

                ID, Venta

                1, 200

                2, 400

                3, 600

                4, 800

                5, 1000

            ];

             

            Fact:

            LOAD

            *,

            IF(Venta < 400, '0-400',

                 IF(Venta >= 400 and Venta <= 600, '400-600',

                      IF(Venta > 600 AND Venta <= 800, '600-800', '800+'))) AS Range_Venta

             

            Resident Temp;

            Drop Table Temp;

             

            Capture.PNG

             

            Added the .QVW as an attachment.

             

            Hope this helps!

             

            Ali A