Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
s4ni9r
Contributor III
Contributor III

Toggle Button to Change the expression in measure.

 

Dear All Qlik Guru's

I have a measure Sum({$<Year={2009}>,<Country={'Sweden'}>} Sales), i want to create a toggle button, like

when i click 'ON' in the button ,  -the expression should  be Sum({$<Year={2009}>,<Country={'Sweden'}>} Sales)

When i click 'OFF' in the button, the expression should  be Sum({$<Year={2009}>} Sales)

Could you please help me with the step by step process for this requirement, i am new to Qliksense, Kindly help me please..

Labels (1)
2 Solutions

Accepted Solutions
Andrei_Cusnir
Specialist
Specialist

Hello,

 

Here are the steps that I have followed to achieve a similar use case scenario:

1. The demo data:

 

2. No I have created a new variable with a default option 1:

 

3. After that I have created a new button and added an action:

  • Actions and navigation
  • Add action
  • Action: Set variable value
  • Variable: vSelected (Do not include "=" as it will fail. For example '=vSelected' will not work)
  • Value: =If($(vSelected) = 1, 2, 1)
  • This will always switch the value from 1 to 2 and from 2 to 1 (Will essentially act like a toggle button)

4. Now I have created a Bar chart, added Year as dimension and as measure added:  =If($(vSelected) = 1, Sum({<Year={2019}, Country={'Sweden'}>} Sales), Sum({<Country={'Sweden'}>} Sales))

 

This will evaluate different expression, based on selected value in the variable.

 

5. As option one I can see:

 

If clicked I can see:

 

As you can see, for option one the expression indicates that we only show the values for Year 2019 and Country Sweden and for expression 2, it will show all the values for Country Sweden for all years. The Bar chart reflects those selections as well.

 

NOTE: Your expression had some issues, so I used slightly modified version of it. First use the expression individually on the chart to ensure that the data is presented as you want them and then use them in the If() statement.

 

I hope that this information was helpful. In case I have misunderstood the use case scenario, please elaborate in details by providing additional information. However, if it has helped you resolve the issue, addressed your concerns or at least pointed you in the right direction, please mark it as Accepted Solution to give further visibility to other community members. 
 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂

View solution in original post

edwin
Master II
Master II

i propose an alternative.  instead of using your variable as a criteria in the if statement, use it to contain your set analysis modifier:

if on  

',<Country={'Sweden'}'

if off

''

then in your expression:

Sum({$<Year={2009}>$(variable)>} Sales)

the advantage is that there is no if statement evaluated for each row.  be careful with the comma at the start of the value for when on

View solution in original post

2 Replies
Andrei_Cusnir
Specialist
Specialist

Hello,

 

Here are the steps that I have followed to achieve a similar use case scenario:

1. The demo data:

 

2. No I have created a new variable with a default option 1:

 

3. After that I have created a new button and added an action:

  • Actions and navigation
  • Add action
  • Action: Set variable value
  • Variable: vSelected (Do not include "=" as it will fail. For example '=vSelected' will not work)
  • Value: =If($(vSelected) = 1, 2, 1)
  • This will always switch the value from 1 to 2 and from 2 to 1 (Will essentially act like a toggle button)

4. Now I have created a Bar chart, added Year as dimension and as measure added:  =If($(vSelected) = 1, Sum({<Year={2019}, Country={'Sweden'}>} Sales), Sum({<Country={'Sweden'}>} Sales))

 

This will evaluate different expression, based on selected value in the variable.

 

5. As option one I can see:

 

If clicked I can see:

 

As you can see, for option one the expression indicates that we only show the values for Year 2019 and Country Sweden and for expression 2, it will show all the values for Country Sweden for all years. The Bar chart reflects those selections as well.

 

NOTE: Your expression had some issues, so I used slightly modified version of it. First use the expression individually on the chart to ensure that the data is presented as you want them and then use them in the If() statement.

 

I hope that this information was helpful. In case I have misunderstood the use case scenario, please elaborate in details by providing additional information. However, if it has helped you resolve the issue, addressed your concerns or at least pointed you in the right direction, please mark it as Accepted Solution to give further visibility to other community members. 
 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂
edwin
Master II
Master II

i propose an alternative.  instead of using your variable as a criteria in the if statement, use it to contain your set analysis modifier:

if on  

',<Country={'Sweden'}'

if off

''

then in your expression:

Sum({$<Year={2009}>$(variable)>} Sales)

the advantage is that there is no if statement evaluated for each row.  be careful with the comma at the start of the value for when on