Skip to main content
Announcements
Join us on Feb.12 to Discover what’s possible with embedded analytics: REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
cmutombo2
Contributor
Contributor

How to let user select columns to be calculted (Sum)

Hi Community 

I am developing a dashboard (App). With fields : "Date", "Movement type",  "Quantity", "Value"

I want to have a formula scenario allow me to select which column will be sum :   

=Sum({$<[=MonthName(Date)]={"$(=MonthName(Addmonths(Date(Today()-1),0)))"}>} Getselected field)

 

By Getselected field, I would like to have a button that will allow me to switch between metrics : "Quantity" or "Value"

 

Thank you in advance.

Christian

 

 

 

 

Labels (1)
6 Replies
brunobertels
Master
Master

hi 

use variable buton in qlik sense 

create a variable using the variable panel give it a name  as vButton and give it 1 as value : 

brunobertels_0-1648548934758.png

 

brunobertels_1-1648548997816.png

 

clik on create new variable 

then add variable buton in your page :

brunobertels_2-1648549087352.png

 

under variable name select the vButton name :

brunobertels_3-1648549158353.png

 

add values : click on add alternative : 

brunobertels_5-1648549329530.png

 

 

Value =1

Name = Value 

 

clik on add alternative : and repeat for 

Value = 2

Name = Quantity 

brunobertels_6-1648549453036.png

 

Then add a variable with for example vSwith in the variable creation panel 

and add this mesure 

if(vButton =1 , 'Value', 'Quantity') : 

brunobertels_7-1648549556575.png

 

In your mesure :

=Sum({$<[=MonthName(Date)]={"$(=MonthName(Addmonths(Date(Today()-1),0)))"}>} $(vSwitch))

 

SunilChauhan
Champion II
Champion II

create this in Variable and put in Set Analysis

VariableName=MonthName(Addmonths(Date(Today()-1),0))

and MonthName(Date)  as MonthName in Script;

then

Sum({$<MonthName={"$(vAriableName"}>} Getselected field)

 

Sum({$<MonthName={'$(vAriableName'}>} Getselected field)

 

Sunil Chauhan
cmutombo2
Contributor
Contributor
Author

 Thanks brunobertels

Firstly,  thanks a lot  for your answer.

I followed correctly steps by steps .

My last formula is : 

=Sum({$<[=MonthName(CREMVTDAT_0)]={"$(=MonthName(Addmonths(Date(Today()-1),0)))"}>}$(vSwitch))

But, Error Message is :

"Error in expression : Sum takes 1 parameter"

Have you an idea ?

regards, 

 

 

 

SunilChauhan
Champion II
Champion II

its due to this  Variable $(vSwitch)

Sum({$<[=MonthName(CREMVTDAT_0)]={"$(=MonthName(Addmonths(Date(Today()-1),0)))"}>} $(vSwitch))

 

why when you use 1 inplace of  $(vSwitch).its howing expresion Ok

 

Sum({$<[=MonthName(CREMVTDAT_0)]={"$(=MonthName(Addmonths(Date(Today()-1),0)))"}>} 1) showing correct 

 

So check this  $(vSwitch) . Here you have issue.

 

Sunil Chauhan
Kashyap_R
Partner - Specialist
Partner - Specialist

Hi

I think u test it by removing the equal sign in your variable or if u have try removing it 

save it and check

sometime variable may give problem based on the output

Thanks and Regards 

Kashyap.R

Thanks and Regards
Kashyap.R
brunobertels
Master
Master

Hi 

vSwitch is attempting to send either "Value" or "Quantity" as name dimension in your mesure Sum() 

let's try to right directly the mesures in the variable vSwtich like that 

if(vButton =1 , 

Sum({$<[=MonthName(Date)]={"$(=MonthName(Addmonths(Date(Today()-1),0)))"}>} Value),

if(vButotn= 2,

Sum({$<[=MonthName(Date)]={"$(=MonthName(Addmonths(Date(Today()-1),0)))"}>} Quantity)

))

where Value and Quantity are the dimension 

Regards