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: 
kvr9
Creator
Creator

Subtraction of two SET Variables

Hello,

I'm stuck with an issue with subtraction. My data contain two variables was trying to subtract them but it is not working properly

Set vCountry=1,

Set vValue =if(vCountry =1,Localcurrency, Localcurrency*exchangerate)

Set vSale =if(vCountry=1,Sales,Sales*exchangerate)

above is the variables I have created for my data and was trying to subtract them as below.

vValue -vSale

I am getting result for local values but not the converted values i.e if country is 0 or more than 1 then it should convert using exchange rates but it is not working as expected

Can some one help me out.

Thanks.

23 Replies
sunny_talwar

May be try with parenthesis

(vValue) - (vSale)

kvr9
Creator
Creator
Author

Hi Sunny,

Sorry missed to mention.I used

sum(vValue) -sum(vSale)

One more point the code is working when I use the expression

sum(if(vCountry =1,Localcurrency, Localcurrency*exchangerate)) - sum(

if(vCountry=1,Sales,Sales*exchangerate)

)

instead of variable that where I'm confused should I use any function before this variables to make the subtraction to work??

sunny_talwar

Are you using an equal sign when you store this in the variable? May be remove the equal sign from the expression and then check

sumanta12
Creator II
Creator II

Hi,

Instead of SET use LET to store value.

kvr9
Creator
Creator
Author

Hi Sunny,

I defined as mentioned above,can you please tell me if any thing wrong in above  statement

HirisH_V7
Master
Master

Hi,

Try this

$(vValue) - $(vSale)

in text box,

where as in expression,

Sum($(vValue) )- Sum($(vSale))

HirisH
“Aspire to Inspire before we Expire!”
kvr9
Creator
Creator
Author

Hi Sumanth,

Since I used set to store the variable I prefixed it with $ while using in expression.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

The variables seem ok, but AFAIK the way you try to use their content is wrong. You don't want to use a LET statement or preliminary variable evaluation by prefixing the string in each with an equal sign. Both lead to either errors or nothing.

You want simple text substitution so that

Sum(Variable)

leads to

Sum(ExpressionInsideVariable)

before the Sum() is calculated. Please try with

=Sum($(vValue)) - Sum($(vSales))

kvr9
Creator
Creator
Author

Hi Peter,

Please find the my expression below.

value.PNG