Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Basic If statement query

Hi everyone,

This will be a very easy one.

I have an expression in my load script and I am doing an if expression   

if((PG = 'CAC' and PG = 'Sa'), 'Y', 'N') as PG_FLAG

I keep getting only N when I do a reload and I know that I should be getting Y.

What's wrong with my script.

Thanks

1 Solution

Accepted Solutions
Not applicable

Basic If statement query

Your set analysis expression is an OR where you are saying PG = 'CAC' or 'SA'.

Logically the value in PG can only be one value or another hence when you use AND the condition can never be true.

Regards,

Gordon

6 Replies

Basic If statement query

Hi,

   Instead of And use Or. like

   if((PG = 'CAC' or PG = 'Sa'), 'Y', 'N')

Regards,

Kaushik Solanki

Re: Basic If statement query

Hi,

Note that QlikView is case sensitive for both field names and values, so the field should be called PG and the possible values in the conditional "CAC" (all uppercase) and "Sa" (mixed).

Besides, one field (PG) cannot have two different values in the same record, so you will have to change it to OR instead of AND, or do something different.

Is that correct?

Miguel Angel Baeyens

BI Consultant

Comex Grupo Ibérica

Not applicable

Basic If statement query

Hi guys,

Thanks for your quick reply.

My field PG has values of Sa, CAC, Ln and so on.

I have a chart with set analysis PG ={'CAC', 'Sa'}

I am just trying to remove the set analysis bit and put it in the script instead to improve performance

Using "OR" will mean it will be Y for either choice. I want it to only be Y for both choices.

I hope I have been clear enough.

Thanks for your anticipated help

Basic If statement query

Hi,

    Yes you are right or means either choice.

    So according to the statement it will only assign Y when your field value is CAC or Sa.

 

    If there is any value other than this, it will assign N.

Regards,

Kaushik Solanki

Not applicable

Basic If statement query

Your set analysis expression is an OR where you are saying PG = 'CAC' or 'SA'.

Logically the value in PG can only be one value or another hence when you use AND the condition can never be true.

Regards,

Gordon

Not applicable

Basic If statement query

Thank you all for your helpful responses

Community Browser