Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Highlighted
dmxmikey
Contributor

if statement

Hi I have an if statement as below

if([p-code]=[p-original],[sell-price-new],[sell-price-new]/[p-master-pack]) as Contract_Selling_Price,

I would like to to and a condition to the above where [p-master-pack] is not 0 to add a value on another field called [split]

Tags (1)
6 Replies

Re: if statement

I would like to to and a condition to the above where [p-master-pack] is not 0 to add a value on another field called [split]

Not sure I understand this... can you may be re-explain?

Re: if statement

No you cant do this way better you add another field on the script for comparing this values and create another flag field. Lets say if they are same then 1 else 0

Data:

Load

if( [p-code]=[p-original],1,0) as FlagCompare

From Source;


Load *,

if( FlagCompare = 1, [sell-price-new], [sell-price-new] / [p-master-pack]) as Contract_Selling_Price

Resident Data;


Drop Table Data;


Re: if statement

Sunny is right, your explanation is a bit dubious in that it leaves much to speculation. For example, where do you want to add this extra clause, outside or inside the current IF call? Is it really 0 you want to test for, or NULL also?

See if this is a correct interpretation:

IF ([p-code] = [p-original], [sell-price-new], [sell-price-new] / [p-master-pack]) +

   IF ([p-master-pack] <> 0, [split], 0) AS Contract_Selling_Price,


Note that in a single column expression you can only manipulate the value of the current field, not two  fields at the same time.

surendraj
Valued Contributor

Re: if statement

Here instead of writing another condition in same if condition,you can do it by

if(is not null( [p-master-pack] ), [p-master-pack] ) as [p-master-pack](split)

after that in seperate load you can mention your condition

if([p-code]=[p-original],[sell-price-new],[sell-price-new]/[p-master-pack]) as Contract_Selling_Price

dmxmikey
Contributor

Re: if statement

meant to say add second condition on same statement

oscar_ortiz
Valued Contributor

Re: if statement

Just a guess as the question is not very clear:

if([p-code]=[p-original] and [p-master-pack] <> 0,[sell-price-new],[sell-price-new]/[p-master-pack]) as Contract_Selling_Price


Good luck

Oscar