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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Shiva123
Creator
Creator

Sum Function Not working Properly

hey ,

         everyone i have this issue which is a simple expression, at the designer end (Front end) is its working fine but at the script level it is not doing the exact calculation as the front end . The calculation here is  Amount / Quantity, where in some of the Amount's are negative and some of the Quantity are Zero's, my question is here is these two factors are causing the problem is there any way t resolve this or a better way to write the expression in script.

Thanks,

Shiva

12 Replies
eduardo_dimperio
Specialist II
Specialist II

Well, if i understand rightly you have this situation:

Amount/Qunatity

Ex:

Produt A: 12/4 + 6/0

Produt B: 30/10 + (-20)/5 + (-3)/0

If so, you can just replace when Quantity = 0 to =1, about negative Amount value i dont think this is a problem.

Shiva123
Creator
Creator
Author

your example is right .. and where to replace the quantity?

woshua5550
Creator III
Creator III

maybe this ?

Load

IF(Quantity=0,0, Amount / Quantity) as Price

From <TableName>

antoniotiman
Master III
Master III

Try this

Alt(Amount/Quantity,0) as NewField

eduardo_dimperio
Specialist II
Specialist II

You can use something like this my friend:

yourtable:

load

field1,

field2,

amount

If(quantity=0,1,quantity) as quantity

from yourqvd.qvd

or in one step like sugest Dave in comment above.

Shiva123
Creator
Creator
Author

tried this one didn't work .. my expression was like this (if(QTY =0,0,sum(Amount)) /Sum(QTY))as [New Filed]   .

is there any thing wrong in my expression? Could You Please Help me out .

Thanks

Shiva

Anil_Babu_Samineni

One extra parenthesis closed in advance after first aggregation sum. Try this

(if(QTY =0,0,sum(Amount) /Sum(QTY))as [New Filed]

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
Shiva123
Creator
Creator
Author

this expression is saying wrong ..

Anil_Babu_Samineni

What do you mean wrong? Throwing any error or returning nothing..

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