Skip to main content

New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
QlikWorld 2023, a live, in-person thrill ride. Save $300 before February 6: REGISTER NOW!
cancel
Showing results for 
Search instead for 
Did you mean: 
alenb
Partner - Contributor III
Partner - Contributor III

How to use variables in chart expressions?

 

 

I get the CurrentMonth  variable in number form like this:

 

Set CurrentMonth = Num(Month(Date#(Month(Today()),'MMM')));

 

 

This variable can be used for displaying values and it works as it should, displays 10 if it's October. 

However if I want to use this variable in the chart expression then it does not work. Compare the below two:

 

sum({$ < BillingMonth = {"<=10"}, BillingYear = {'2020'}>  } Units)

 

Above expression works.

 

sum({$ < BillingMonth = {"<=$(CurrentMonth)"}, BillingYear = {'2020'}>  } Units)

 

 

This one does not, it is evaluated as correct but returns 0, while the top one nicely returns sales for all months in the year 2020 that are equal or smaller than 10.

I also tried with double dollar, and again the expression is correct but returns 0.

 

 

sum({$ < BillingMonth = {"$(<=$(CurrentMonth))"}, BillingYear = {'2020'}>  } Units)

or without double quotes

sum({$ < BillingMonth = {$(<=$(CurrentMonth))}, BillingYear = {'2020'}>  } Units)

 

 

 




Labels (1)
1 Solution

Accepted Solutions
Kushal_Chawda

@alenb  try to use floor instead num and also try to evaluate expression within variable using Let instead of set. Then you can use that variable in set analysis

Let CurrentMonth = floor(Month(Date#(Month(Today()),'MMM')));

 

View solution in original post

2 Replies
Kushal_Chawda

@alenb  try to use floor instead num and also try to evaluate expression within variable using Let instead of set. Then you can use that variable in set analysis

Let CurrentMonth = floor(Month(Date#(Month(Today()),'MMM')));

 

alenb
Partner - Contributor III
Partner - Contributor III
Author

It was the "Let" vs "Set", thanks man! I'm a senior programmer but very new to Qlik and I think I will never get used to the differences between Let and Set 🙂