Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
DSDD
Contributor III
Contributor III

Functions as a variable

Dear community,

i want to let the user choose between average and median in buttons.

So, is it possible to take the Avg and Median function in a variable, let say v_fun?

And how to evaluate functions within the variable on my dimension, let say body_weight? (How does the syntax look like?)

Thanks

Labels (2)
1 Solution

Accepted Solutions
MayilVahanan

Hi @DSDD 

Create a variable and assign the value like below

variable name: v_fun

value: Avg($1)

In chart, ur dimension and expression is like

$(v_fun(body_weight))

-- gives average of body_weight based on ur dimension

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

3 Replies
MayilVahanan

Hi @DSDD 

Create a variable and assign the value like below

variable name: v_fun

value: Avg($1)

In chart, ur dimension and expression is like

$(v_fun(body_weight))

-- gives average of body_weight based on ur dimension

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
DSDD
Contributor III
Contributor III
Author

Thanks for your answer. It works.

What does $1 achieve in this context, especially when $(v_fun(body_weight)) is evaluated?

MayilVahanan

Hi @DSDD 

$1 here is works like parameter, you can pass any field name.

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.