Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Using user defined function in expression

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? 

1 Solution

Accepted Solutions
swuehl
MVP
MVP

You can look into dollar-sign-expansion with parameter:

Dollar-Sign Expansion with Parameters

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

View solution in original post

3 Replies
Not applicable
Author

You can use variables instead.

swuehl
MVP
MVP

You can look into dollar-sign-expansion with parameter:

Dollar-Sign Expansion with Parameters

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

Anonymous
Not applicable
Author

Thanks for this suggestion and I am not aware of this useful feature in Qlikview!