Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

if statement issue

im using qlikview 8.5 In the edit expression, I have added this

OldBatteryPurchasePrice >0, (((amt  + OldBatteryPurchasePrice)- Items_Dealerprice) / Items_Dealerprice ) * 100

and work prefectly, no issues............

but I have some condition

I have few rows, where oldbatterypurchaseprice row does not contain value, for that, I have to use different formula to calculate the profit

im trying the below if conditions, but it is not working... thanks

If(  OldBatteryPurchasePrice >0, (((amt  + OldBatteryPurchasePrice)- Items_Dealerprice) / Items_Dealerprice ) * 100 )

and

If(OldBatteryPurchasePrice=' ', ((amt  - Items_Dealerprice) / Items_Dealerprice ) * 100 )

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Try

len(trim(OldBatteryPurchasePrice)) = 0:

If(  OldBatteryPurchasePrice >0,

     (((amt  + OldBatteryPurchasePrice)- Items_Dealerprice) / Items_Dealerprice ) * 100,

     If( len(trim(OldBatteryPurchasePrice))=0, ((amt  - Items_Dealerprice) / Items_Dealerprice ) * 100 )

)

View solution in original post

4 Replies
swuehl
MVP
MVP

In general, you can check your second condition in the else-branch of the first if()-statement:

If(  OldBatteryPurchasePrice >0,

     (((amt  + OldBatteryPurchasePrice)- Items_Dealerprice) / Items_Dealerprice ) * 100,

     If(OldBatteryPurchasePrice=' ', ((amt  - Items_Dealerprice) / Items_Dealerprice ) * 100 )

)

john_s_w_wood
Creator
Creator

Hope I have the gist of your issue.Not now familiar with v8.5, but on first sight I would say you are missing aggregation formula. Generally, but not always the aggregation should be outside the if statement so try;

sum(If(  OldBatteryPurchasePrice >0, (((amt  + OldBatteryPurchasePrice)- Items_Dealerprice) / Items_Dealerprice ) * 100 ),

If(OldBatteryPurchasePrice=' ', ((amt  - Items_Dealerprice) / Items_Dealerprice ) * 100 )))

Note I have changed your statement to a nested if;

if(a =1,3,if(a=4,7))

the whole statement has been enclosed with a sum(xxxxxx) statement

Hope this helps

Not applicable
Author

if statement is working, but

OldBatteryPurchasePrice=' ', i could not figure out, if there is no value in the row, should i use double single quotes or???

swuehl
MVP
MVP

Try

len(trim(OldBatteryPurchasePrice)) = 0:

If(  OldBatteryPurchasePrice >0,

     (((amt  + OldBatteryPurchasePrice)- Items_Dealerprice) / Items_Dealerprice ) * 100,

     If( len(trim(OldBatteryPurchasePrice))=0, ((amt  - Items_Dealerprice) / Items_Dealerprice ) * 100 )

)