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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to sum with a variable

hi, so I created a variable in settings and now I want to use this variable when summing up things.

Variable: Turnover

trade_price*traded_amount

Expression:

sum(If(IsNull(sub_exec_broker),Turnover))

Labels (1)
17 Replies
Anonymous
Not applicable
Author

Hi Niklas,

Why have you created this var? Do it more simple: Sum(If(IsNull(sub_exec_broker),trade_price*traded_amount).

Other option is: Sum({<sub_exec_broker={'*'}>}trade_price*traded_amount), here you will sum all values for your product, but only when sub_exec_broker has value.

Third option is use variable functions:

Your Variable: Sum({<$1={$2}>},$3*$4)

Your Expression: $(YourVarName(sub_exec_broker,'*',trade_price,traded_amount))

It will be translated like this: Sum({<sub_exec_broker={'*'}>}trade_price*traded_amount)

Regards!

its_anandrjs
Champion III
Champion III

In any text object or the chart check what output you get from the below expression

IsNull( sub_exec_broker )

and then use that condition to check for Isnull() function, Also Isnull() function return -1 if the condition is true.

Regards,

Anand

Not applicable
Author

Hey Manuel,

Thanks but the reason is:

sum(If(IsNull(sub_exec_broker),(trade_price*traded_amount)))

This works but I need to make further calculation.

sum(If(IsNull(sub_exec_broker),(trade_price*traded_amount/rate_eur*rates)))

should give me the final and expected value but this doesnt work. This just gives me 0 in an expression therefor I was trying to make it with a variable. If you undestand? Maybe you have another suggestion in doing this?

trdandamudi
Master II
Master II

I think the reason you are not getting the result because the field sub_exec_broker value is not a real null. So use the below expression: Hope this helps....

sum(If(Len(Trim(sub_exec_broker))=0,$(Turnover) ))

Anonymous
Not applicable
Author

Hi Niklas,

Try this:

sum(

     If(

          LEN(Replace(Replace(sub_exec_broker,' ',''),Chr(10),''))=0, //Here you can have some chars, i deleted returns and blanks

     (trade_price*traded_amount) /   //be carefull with operators priority

     (rate_eur*rates)

     )

)

Regards!!!

Not applicable
Author

Untitled.png

You see the picture above. Turnover is calculated by using this expression:

sum(If(IsNull(sub_exec_broker),trade_price*traded_amount)) <- Works fine!

Then I want to jsut convert it to EUR in second column by just adding:

sum(If(IsNull(sub_exec_broker),trade_price*traded_amount/rate_eur))


And it is not working. Any suggestions?

Not applicable
Author

The only reason for this issue is that the rate_euro is null where the sub_exec_broker is empty.

Your data should be like this :

 

exec_brokersub_exec_brokertraded_amounttrade_pricerate_eur
AA124000101,2
L 500010
MM119000101,2
MM218000101,2
PP117000101,2
P 500010
S 600010
Anonymous
Not applicable
Author

sum(If(IsNull(sub_exec_broker),trade_price*traded_amount/If(IsNull(rate_eur),1,rate_eur)))