Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Help with If Statement

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

2 Replies
m_woolf
Master II
Master II

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

bwisealiahmad
Partner - Specialist
Partner - Specialist

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