Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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.
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.
Quick question - Where am I declaring these variables? I mean is it under - Edit Module or Variable Overiew window?
Thanks again.
Cheers - DV
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)