Discussion Board for collaboration related to QlikView App Development.
Can I use user defined function in expression?
I have an expression that is quite long and need to be reused in different expressions. It also gives different results based on the input (parameter)
Can I put it in an user defined function so that I can call it in different expressions of a chart?
You can look into dollar-sign-expansion with parameter:
Parameters can be used in variable expansions. The variable must then contain formal parameters, such as $1, $2, $3 etc. When expanding the variable, the parameters should be stated in a comma separated list.
Examples:
set MUL=’$1*$2’;
set X=$(MUL(3,7)); // returns '3*7' in X
let X=$(MUL(3,7)); // returns 21 in X
If the number of formal parameters exceeds the number of actual parameters only the formal parameters corresponding to actual parameters will be expanded. If the number of actual parameters exceeds the number of formal parameters the superfluous actual parameters will be ignored.
Examples:
set MUL=’$1*$2’;
set X=$(MUL); // returns '$1*$2' in X
set X=$(MUL(10)); // returns '10*$2' in X
let X=$(MUL(5,7,8)); // returns 35 in X
The parameter $0 returns the number of parameters actually passed by a call.
Example:
set MUL='$1*$2 $0 par';
set X=$(MUL(3,7)); // returns '3*7 2 par' in X
You can use variables instead.
You can look into dollar-sign-expansion with parameter:
Parameters can be used in variable expansions. The variable must then contain formal parameters, such as $1, $2, $3 etc. When expanding the variable, the parameters should be stated in a comma separated list.
Examples:
set MUL=’$1*$2’;
set X=$(MUL(3,7)); // returns '3*7' in X
let X=$(MUL(3,7)); // returns 21 in X
If the number of formal parameters exceeds the number of actual parameters only the formal parameters corresponding to actual parameters will be expanded. If the number of actual parameters exceeds the number of formal parameters the superfluous actual parameters will be ignored.
Examples:
set MUL=’$1*$2’;
set X=$(MUL); // returns '$1*$2' in X
set X=$(MUL(10)); // returns '10*$2' in X
let X=$(MUL(5,7,8)); // returns 35 in X
The parameter $0 returns the number of parameters actually passed by a call.
Example:
set MUL='$1*$2 $0 par';
set X=$(MUL(3,7)); // returns '3*7 2 par' in X
Thanks for this suggestion and I am not aware of this useful feature in Qlikview!