Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Qlik Expressions (Direct vs. Set Operations)

Hi - I am wondering what's the difference between typing in directly in the Expression (fx) box directly vs. creating a set operations.


I am baffled a bit because this expression below works perfectly when I write directly in the expression(fx) box: 

sum({<date = {'>=$(=MonthStart(Max(date)))'}>*<date = {'<=$(=MonthEnd(Max(date)))'}>}amount)

But when I create this set expression, current month amount, I get an incorrect answer: 

set current_month_amount= "sum({<date = {'>=$(=MonthStart(Max(date)))'}>*<date = {'<=$(=MonthEnd(Max(date)))'}>}amount";

Any help is appreciated.

4 Replies
krishna_2644
Specialist III
Specialist III

If you are setting up/storing the expression in a variable, then you have to use $(vVariable) in your other expression wherever you are using this variable.hope that helps.

Anonymous
Not applicable
Author

Hello, I do call $(current_month_amount), but the amount it gives is incorrect.

krishna_2644
Specialist III
Specialist III

please post your expressions with some sample data.

jonathandienst
Partner - Champion III
Partner - Champion III

The problem is that the $ expansions (DSE) are executing even though you may not expect it in a Set statement. You need to break up the DSEs to prevent them executing at this point. You can do this

Set current_month_amount = Sum({<date = {'>=#(=MonthStart(Max(date)))'}> * <date = {'<=#(=MonthEnd(Max(date)))'}>}amount;

Let current_month_amount = Replace(current_month_amount, '#', '$');

or this

Let current_month_amount = "sum({<date = {'>=$" & "(=MonthStart(Max(date)))'}> * <date = {'<=$" & "(=MonthEnd(Max(date)))'}>}amount";

This is only a  problem if the expression is defined in the script on in an inline load. It is not a problem if it is read from an external source.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein