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

Need help in understanding the Expression..?

Hi all,

I have seen on e expression, which is like : Sum(-(Amnt>0)*Amnt)

Why we have to write like this , what is the need , since we have got Amnt already in expression.

why we have to use sum(-(Amnt>0)) extra..

Thanks...

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Amnt>0   returns -1 (True) or 0 (False). Hence  Sum(-(Amnt>0)) sums -(-1) (i.e. 1) for values of Amnt greater than zero. Hence the entire expression is actually equivalent to  Sum(If(Amnt>0, Amnt,0)).

View solution in original post

5 Replies
tresesco
MVP
MVP

Amnt>0   returns -1 (True) or 0 (False). Hence  Sum(-(Amnt>0)) sums -(-1) (i.e. 1) for values of Amnt greater than zero. Hence the entire expression is actually equivalent to  Sum(If(Amnt>0, Amnt,0)).

alexandros17
Partner - Champion III
Partner - Champion III

Sum(-(Amnt>0)*Amnt)


If Amnt>0 is true then the expression become: Sum(-(-1)*Amnt) that is Sum(Amnt)

If amnt>0 is false then Sum(-(0)*Amnt) that is 0


We are summing only positive values for amount

struniger
Creator
Creator

This will give you a value of decimal zero when you have a negative figure in Amnt, thus only summing up positive values.

The expression (Amnt>0) will either return True (-1) or False (0)

Hope this helps to clear up your question.

Best regards

Stefan

Not applicable
Author

Hi tresesco,

Thanks for your reply, that is ok but.. why we have to use this Sum(-(Amnt>0)), instaed directly we can use

Sum(Amnt) rt..?

tresesco
MVP
MVP

If you have negative values in Amnt, they would not be summed. Sum(Amnt) - sums all irrespective of if Amnt is positive or negative. Hope this helps.