Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

use of variable to change expression from sum to median

Hi all.

I'm trying to figure out how to use a variable ti change expressions from sum to median.

I want a variable to hold sum/median and let the user decide which expression he want to see all over the board,

so i want my expression to be something like:

=$(var)(Sales)

=$(var)(Unit)

but the above isn't working.

any ideas?

Thanks,

Raz.

4 Replies
jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

=If(variable = 'Sum', Sum(Sales), Median(Unit))

Regards,

Jagan.

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

     You can create one variable which will change according to the users input in the Field.

     Say for example, the Field is KPI and the values are SUM and Median.

     then Create a variable with below expression.

     =if(Getfieldselections(KPI) = 'SUM',Sum(Sales),Median(Sales))

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Guys,

I'm not sure i'm follwing you, or your solutions is not what i'm looking for.

I already have

sum(sales)

sum(unit)

...

etc'

Now i want to add median.

But i don't want to multiply my expression, and i don't want to replace each expression by variable.

I want to be able to only replace the function for a variable in each expression. is it possible?

Thanks again.

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Dear Raz,

     If you want to use the variable, then this is the easiest way and effective way of doing this.

     Or else you can use the "Conditional" option of the expression where you can enable and disable the expression according to some condition.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!