Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
The #1 reason QlikView customers adopt Qlik Sense is a desire for a modern BI experience. Read More
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
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
Highlighted

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?

Highlighted

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;


Highlighted

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.

Highlighted
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

Highlighted
Creator
Creator

meant to say add second condition on same statement

Highlighted
Partner
Partner

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