Qlik Community

Qlik Sense Cloud Discussions

talri564
New Contributor

assigning a formula into a variable

Hi Guys,

I Am trying to assign a simple formula into a variable, but i don't know how to do that in Qlik.

for example in SQL i would to this:

Sum(CostPrice-Discount) AS 'Subs'

How do i do this in Qlik Sense?

Thanks a lot

4 Replies
atkinsow
Valued Contributor II

Re: assigning a formula into a variable

in the script you would do

LET Subs = 'sum(CostPrice-Discount)';

or

Set Subs = 'sum(CostPrice-Discount)';


depending on how you're intending to use it.

talri564
New Contributor

Re: assigning a formula into a variable

Hi Wallo,

Thank you for your answer, but it doesn't work

Probably, because I am not trying to do that in the script, but in the 'Expression Editor'

I am trying to edit an expression and add a calculated field

Any other suggestions?

Thanks

atkinsow
Valued Contributor II

Re: assigning a formula into a variable

A little confused.    Why wouldn't you just do Sum(CostPrice-Discount)  in your expression editor?  Or is discount or costprice a calculation as well?

talri564
New Contributor

Re: assigning a formula into a variable

Because it's a formula of a few variables, each of them is like 2 lines long, so i want to set each one of them to a variable. Otherwise the formula is going to be a long mass :-P

Community Browser