Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

combine 4 if statements into a single expression. need help..pl???

hi all,

Please request help on the below issue.

I have 4 if statements below and  t,I am not able to resolve it,please can anyone help me out???

i AM NOT GOOD IN NESTED IF'S SO PLEASE CAN SOMEONE HELP ME WITH THIS????????????

1)if( market_value_1<= strike_price,-1*(premium),((-1*(premium)+ (market_value_1-strike_price))))  and  ([Buy/Sell]='BUY' AND xoptiontype='CALL'

2) if( market_value_1<= strike_price,+1*(premium),((+1*(premium)- (market_value_1-strike_price))))  and  ([Buy/Sell]='SELL' AND xoptiontype='CALL'

3)    if( market_value_1<= strike_price,((-1*(premium)+ (strike_price-market_value_1))),-1*(premium))  and  ([Buy/Sell]='BUY' AND xoptiontype='PUT'

  4)  if( market_value_1<= strike_price,((+1*(premium)- (strike_price-market_value_1))),+1*(premium))  and  ([Buy/Sell]='SELL' AND xoptiontype='PUT'

I HAVE ATTACHED THE FILE FOR REFERENCE.

In them the 4 columns buy_call,buy_put,sell_call and sell_put are differently displayed which needs to be combined to a single column with the extra contion for esch case:

([Buy/Sell]='BUY' AND xoptiontype='CALL'  etc.. as shown above.

1 Solution

Accepted Solutions
crusader_
Partner - Specialist
Partner - Specialist

Sorry, can't open your sample.

Anyway

if( [Buy/Sell] = 'buy ' and xoptiontype = 'call', then expression1,

     if(   [Buy/Sell] = 'sell ' and xoptiontype = 'call',  then expression2,         

           if(   [Buy/Sell] = 'buy ' and xoptiontype = 'put',  then expression3,

                    if(   [Buy/Sell] = 'sell ' and xoptiontype = 'put',  then expression4,

                              else expression

               )

     )   

) as Result

HTH

Andrei

View solution in original post

11 Replies
crusader_
Partner - Specialist
Partner - Specialist

Hi,

You use same condition for all 4 if statements?

market_value_1<= strike_price

or [Buy/Sell]='BUY' AND xoptiontype='CALL'  condition too?


Where do you use this expressions in LOAD statement or in chart?


Andrei

Not applicable
Author

Hi Andrei,

I want to put these in script itself but the field market_value1 is coming from different resident and the other fields from different residents,so I do not know how to do it.If you can put it in script it would be great.

you can combine the 4 expression into one single column 'value', which could be pulled in expression part in the chart.

Each condition is different :last part is combination for the 4 conditions

buy call

sell call

buy put

sell put

crusader_
Partner - Specialist
Partner - Specialist

Sorry, can't open your sample.

Anyway

if( [Buy/Sell] = 'buy ' and xoptiontype = 'call', then expression1,

     if(   [Buy/Sell] = 'sell ' and xoptiontype = 'call',  then expression2,         

           if(   [Buy/Sell] = 'buy ' and xoptiontype = 'put',  then expression3,

                    if(   [Buy/Sell] = 'sell ' and xoptiontype = 'put',  then expression4,

                              else expression

               )

     )   

) as Result

HTH

Andrei

Not applicable
Author

thanks a lot Andrei.

Not applicable
Author

Hi Andrei,

I tried to combine the 4 if's as you said but somehow the result is not correct,as I am not sure with the brackets .Can you please check in the attached file and please correct the same.

Not applicable
Author

Hi Andrei ,

can you please help me out on the above issue please??????????????????????

the combined column should match with the rest individual ones buy_call,sell_call,buy_put and sell_put....

anbu1984
Master III
Master III

Try this

if( [Buy/Sell] = 'buy ' and xoptiontype = 'call', expression1,

     if(   [Buy/Sell] = 'sell ' and xoptiontype = 'call',  expression2,        

           if(   [Buy/Sell] = 'buy ' and xoptiontype = 'put',  expression3,

                    if(   [Buy/Sell] = 'sell ' and xoptiontype = 'put',  expression4,

                              expression

               )

     )  

)

)

Not applicable
Author

yes,

I tried this but the else condition varies for all 4 conditions ,hence I am stuck there.please can you  help.???????

if( buy_sell = 'BUY' and xoptiontype_ = 'CALL'and market_value_1 <= strike_price,-1*(premium),((-1*(premium)+ (market_value_1-strike_price))

,

     if(   buy_sell = 'sell ' and xoptiontype_ = 'call' and market_value_1 <= strike_price,+1*(premium),((+1*(premium)- (market_value_1-strike_price))))

,        

           if(   buy_sell = 'buy ' and xoptiontype_ = 'put' and market_value_1 <= strike_price,((-1*(premium)+ (strike_price-market_value_1))),-1*(premium)) 

,

                    if(   buy_sell = 'sell ' and xoptiontype_ = 'put' and market_value_1 <= strike_price,((+1*(premium)- (strike_price-market_value_1))),+1*(premium))  

,

                             

               )

     )  

))

anbu1984
Master III
Master III

Suppose If buy_sell = 'BUY' and xoptiontype_ = 'CALL', then your expression is -1*(premium). In this case, do you want run else statement of other three if statements and add their result to -1*(premium)?