Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
dmxmikey
Creator
Creator

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]

6 Replies
sunny_talwar

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?

its_anandrjs

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;


Peter_Cammaert
Partner - Champion III
Partner - Champion III

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
Specialist
Specialist

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
Creator
Creator
Author

meant to say add second condition on same statement

oscar_ortiz
Partner - Specialist
Partner - Specialist

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