Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
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
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

3 Replies
Not applicable
Author

You can use variables instead.

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!

Community Browser