Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join us for a live Q&A! September 21, 10 AM ET - Onboarding Fast in Qlik Sense SaaS! REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
IAMDV
Luminary Alumni
Luminary Alumni

How to encapsulate complex expressions in to variable?

I have few complex expressions in my document. I wanted to assign this expression calculation to variable or like a UDF?

Thanks in advance.

Cheers - DV

1 Solution

Accepted Solutions
gandalfgray
Specialist II
Specialist II

To encapsulate expressions in a variable simply do like this:


Set eValue = 'if(vFlag = 1, Value1, Value2)';


You can also use previousy defined variables inside variables, like this for instance:


Let CurrentMonth = Left(PurgeChar(vToDay,'-'),6);
Let SelectedCurrentMonth = CurrentMonth;
Let PrevMonth = Left(PurgeChar(AddMonths(vToDay,-1),'-'),6);
Set ExclDateSelectsAll = 'Year=, Date=, YearQtr=, WeekYear=, Month=, Quarter=, Week=, WeekDay=, Day=';
Set eValue = 'if(vFlag = 1, Value1, Value2)';
Set eInvoiced = 'if(SelectedCurrentMonth=CurrentMonth,
Sum({$<YearMonth={"$(CurrentMonth)"}, $(ExclDateSelectsAll)>} $(eValue)),
Sum({$<YearMonth={"$(PrevMonth)"}, $(ExclDateSelectsAll)>} $(eValue)))';


When you want to access the values of these expressions you need to use dollar-sign expansion, like this: $(eInvoiced)

Also note that when using a variable inside the definition of another variable you should also use dollar-sign expansion, like in my examples.

View solution in original post

3 Replies
gandalfgray
Specialist II
Specialist II

To encapsulate expressions in a variable simply do like this:


Set eValue = 'if(vFlag = 1, Value1, Value2)';


You can also use previousy defined variables inside variables, like this for instance:


Let CurrentMonth = Left(PurgeChar(vToDay,'-'),6);
Let SelectedCurrentMonth = CurrentMonth;
Let PrevMonth = Left(PurgeChar(AddMonths(vToDay,-1),'-'),6);
Set ExclDateSelectsAll = 'Year=, Date=, YearQtr=, WeekYear=, Month=, Quarter=, Week=, WeekDay=, Day=';
Set eValue = 'if(vFlag = 1, Value1, Value2)';
Set eInvoiced = 'if(SelectedCurrentMonth=CurrentMonth,
Sum({$<YearMonth={"$(CurrentMonth)"}, $(ExclDateSelectsAll)>} $(eValue)),
Sum({$<YearMonth={"$(PrevMonth)"}, $(ExclDateSelectsAll)>} $(eValue)))';


When you want to access the values of these expressions you need to use dollar-sign expansion, like this: $(eInvoiced)

Also note that when using a variable inside the definition of another variable you should also use dollar-sign expansion, like in my examples.

View solution in original post

IAMDV
Luminary Alumni
Luminary Alumni
Author

Quick question - Where am I declaring these variables? I mean is it under - Edit Module or Variable Overiew window?

Thanks again.

Cheers - DV

gandalfgray
Specialist II
Specialist II

Hi,

I would do it in Edit Script (Ctrl-E) (that is: in the load script)

(maybe in variable overview, but not in Edit Module anyway)

Smile