Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

The opposite expression evaluation occurs

Maybe I have been looking at this code for too long.

if(Trim(QTrnType)<>'IC',QQty,-1*QQty) as UQty,

For the above example the output of the expression looks like this

QTrnType is IC, QQty is 1 and UQty is -1

QTrnType is IN, QQty is 1 and UQty is 1

QTrnType is IT, QQty is 2 and UQty is 2

if(Trim(QTrnType)='IC',QQty,-1*QQty) as UQty,

In the above example the opposite happens????

QTrnType is IC, QQty is 1 and UQty is 1

QTrnType is IN, QQty is 1 and UQty is -1

QTrnType is IT, QQty is 2 and UQty is -2

I would expect the output of these examples to be the opposite - to be + and visa versa???

Any ideas?

Thanks

1 Solution

Accepted Solutions
Gysbert_Wassenaar

The if statement works like this:

If( condition, expression1, expression2)

if condition is true then evaluate expression1, if condition is false then evaluate expression2

if(Trim(QTrnType)<>'IC',QQty,-1*QQty) as UQty

QTrnType is IC -> trim(QTrnType)<>'IC' is False -> multiply QQty with -1 -> result: -1

if(Trim(QTrnType)='IC',QQty,-1*QQty) as UQty

QTrnType is IC -> trim(QTrnType)='IC' is True-> take QQty -> result: 1

<> is the opposite of =, so the results are the opposites too.


talk is cheap, supply exceeds demand

View solution in original post

2 Replies
Gysbert_Wassenaar

The if statement works like this:

If( condition, expression1, expression2)

if condition is true then evaluate expression1, if condition is false then evaluate expression2

if(Trim(QTrnType)<>'IC',QQty,-1*QQty) as UQty

QTrnType is IC -> trim(QTrnType)<>'IC' is False -> multiply QQty with -1 -> result: -1

if(Trim(QTrnType)='IC',QQty,-1*QQty) as UQty

QTrnType is IC -> trim(QTrnType)='IC' is True-> take QQty -> result: 1

<> is the opposite of =, so the results are the opposites too.


talk is cheap, supply exceeds demand
Not applicable
Author

Thank you Gysbert