Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
SonPhan
Partner - Creator
Partner - Creator

Using Functions like in programming language

Hi Qlik-Experts,

Is there a way to define a function on the surface in QS that can take parameter values as input?

For example
Calc(A, B) {
return A+B}

If you now define for example Calc(3,5) as KPI 8 should be output.

 

Thank you for your support

1 Solution

Accepted Solutions
Or
MVP
MVP

On the script level, you can use Sub ... End Sub. https://help.qlik.com/en-US/sense/September2019/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptCon...

At the object (front end) level, I believe the best solution is to use a variable with $ expressions, e.g. as described here: https://community.qlik.com/t5/QlikView-App-Dev/create-custom-function-with-parameter/td-p/147066

 

View solution in original post

3 Replies
Or
MVP
MVP

On the script level, you can use Sub ... End Sub. https://help.qlik.com/en-US/sense/September2019/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptCon...

At the object (front end) level, I believe the best solution is to use a variable with $ expressions, e.g. as described here: https://community.qlik.com/t5/QlikView-App-Dev/create-custom-function-with-parameter/td-p/147066

 

ArnadoSandoval
Specialist II
Specialist II

Hi @SonPhan 

If you want to implement these function inside the load script, yes, you can, I compiling a document about variables, I already wrote and tested this section:

Multi-Parameters Function as Variables

We could define multi-parameters functions as well, we declare them with a LET in the load script, while we just create them as usual in the sheet’s variables section; in this example we consume the function at 3 different places:

  1. Load script’s declaration.
  2. Load script’s calculation.
  3. Load script’s dynamic column.
  4. UI’s Charts.

Multi-Variable-Function-01.png

Comments:

  • We declared and consume a two parameters variable function in the script.
  • We did a calculation with it, printing its output to the load script log.
  • We reference the variable function as a column returning a dynamic value defined by the variable function.
  • We consumed the variable function in the UI as part of a Text and Image element.

Function Variables Summary

  1. They are single line function.
  2. They could be consumed anywhere in the application, script or user interface.
  3. We haven’t seen them documented in the Qlik Help pages.

Hope this helps,

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.
ArnadoSandoval
Specialist II
Specialist II

Hi @SonPhan 

This is the topic where Function Variables was explained Click Here 

Arnaldo Sandoval
A journey of a thousand miles begins with a single step.