Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
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
MVP
MVP

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
MVP
MVP

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
MVP
MVP

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.