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

how to use button to control line chart expression?

Hi there, i am using qlik sense - Variable Input Object to control to show Sales Value in ($ value) and sales value(%) in percentage. 

i managed to get the function right, as in click this button it show value, click another button to change to percentage failed!

this formula is percentage formula. you can see from the axis y,  it only show the value 0, 5, 10. by right is 0% , 5%, 10%.

jim_chan_0-1653647094788.png

 

and the label, how to get the % as well?

jim_chan_1-1653647182792.png

 

Currently, since i am using Variable Input, my formula is as such:

pick(vmeasure,$(=$(vSumValue_P(1)))/count(distinct Date),

(sum({<SALES_DAY={"$(vDateRange1)"}>}SALES)
/
sum(TOTAL{<SALES_DAY={"$(vDateRange1)"}>}SALES))
*100
)

Which part in this script that i can modify? 

Or, is there another way? 

all i need is a 2 buttons, 1 for value , 1 for percentage. and 1 expression line - if showvalue then this expression, if showpercentage, then this expression.

Rgds

Jim

 

 

 

3 Replies
stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @jim_chan 

Have you looked at using Alternate Measures? They may make your problem go away.

However, if you want to fix what you have, you will need to change the number format to Auto and set the number format on each expression with the num function. This allows you to specify in the expression itself how the number is formatted:

pick(vmeasure,
num($(=$(vSumValue_P(1)))/count(distinct Date), '#,##0.0'),
num((sum({<SALES_DAY={"$(vDateRange1)"}>}SALES)
/
sum(TOTAL{<SALES_DAY={"$(vDateRange1)"}>}SALES)), '#,##0.0%')
)

Note that when the num function is used to format a percentage you don't need to multiply by 100, the formatted value will appear as a percentage even though it is a decimal fraction.

I might also clean things up a bit by creating a variable for each expression (with the num function around it) such as vValue and vPerc, and then have the value in vmeasure change from Value to Perc on the button press.

The measure on the chart would then be as simple as:

$(v$(vmeasure))

The nested variable is perhaps a little confusing, but I think it is quite an elegant bit of syntax that Qlik allows you to do, particularly if you want to expand to many expressions, rather than just two.

Hope that helps.

Steve

 

jim_chan
Specialist
Specialist
Author

Hi Steve, 

i did changed already in the line measurement. but,  the y Axis, its stil not showing 0% - 100%, instead, is 0.0 and 0.1. 

 

jim_chan_0-1653698453877.png

 

rgds

jim

 

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @jim_chan 

You seem to have both the button and alternate measures now. Can you please try with just a single measure. Can you also confirm that the number format is set to zero, it will override the num function otherwise. 

Steve