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

If Condition is not working as expected in script or expression

Hi Folks,

Very strange, simple If condition is not working as expected. Whenever I used in the text box, it shows null and in the script, It's throwing the error as invalid expression. Can anyone suggest me why it behaves like this?

If condition  I am loading at load statement in the script by taking resident.

IF([Type]='Champion',0,IF(Sum([Sales])<=(Sum([LP])*Sum([Quantity])),(Sum([ Net Price])*Sum([Discount])))) as Test

The expected output is, Type=Champion is not there in my current data, It should goes to else part to Second If condition.

Sum(Sales) =1158 and Sum(LP)* Sum(Quantity) =1158 so, I need Sum(Net Price)* Sum(Discount) amount.

Thanks

Krishna

Labels (3)
12 Replies
krishna20
Specialist II
Specialist II
Author

Hi Chris,

Thanks for yours input. As I already mentioned above in the comments, my first priority is to write the expression at front end only. 

I am using the fields in the expression are correctly and it is not highlighting any error in the expression window.

This is very strange behavior I am facing with Qlik, no clue how it is working.

Anil_Babu_Samineni

Hey, I don't see any issue from your screenshot? Do you think this is not working as expected (I can assume only based on Measure titles)?

IF([Type]='Champion',0,IF(Sum([Sales])<=(Sum([LP])*Sum([Quantity])),(Sum([ Net Price])*Sum([Discount])))) 

From above, Red part will fail, So condition will fulfill from blue part and get the result of Green part? Is that not what you are expecting?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
krishna20
Specialist II
Specialist II
Author

Hi Anil,

Yes, I need the green part to be calculated. I fixed this issue by taking all above expression to backend and group by with all the dimensions. Don't know why it was not calculating at front end even though the second condition satisfies. Thanks for your inputs and @forte .

Thanks 

Krishna