Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
WojtekSiczek
Contributor
Contributor

Toggle expression in chart based on listbox

Hello everyone,

I have faced a problem I cannot solve myself. I want to toggle the expression in chart to show unit or value based on listbox selection. Everything works fine unless I add comparison to the previous year. Only than the expression is not changed for previous year periods that have no corresponding figures this year.

this is my script:

LOAD

left(period,4) as rok,
right(period,2) as tydzien,
unit,
value

INLINE [
period, unit, value
202001, 201, "558,78"
202002, 202, "561,56"
202003, 203, "564,34"
202004, 204, "567,12"
202005, 205, "569,9"
202006, 206, "572,68"
202007, 207, "575,46"
202008, 208, "578,24"
202009, 209, "581,02"
202010, 210, "583,8"
202101, 211, "586,58"
202102, 212, "589,36"
202103, 213, "592,14"
202104, 214, "594,92"
];

LOAD * INLINE [
F1
u
v
];

When 'u' is selected the Year-1 expression is changed only for weeks 01-04 while weeks 05-10 remains values.

Bez tytułu.png

Any idea for workaround? Thanks in advance.

1 Solution

Accepted Solutions
edwin
Master II
Master II

you can create a variable to hold the measure:
vMeasure:  =if(only(F1)='u','unit','value')  //this will return the field/measure you want to sum
in your expression:
=sum({.....}$(vMeasure))  //the variable will resolve to the desired measure.

depending on the measure you select, it will use the appropriate field:

edwin_0-1612814791783.png

 

View solution in original post

4 Replies
edwin
Master II
Master II

you can create a variable to hold the measure:
vMeasure:  =if(only(F1)='u','unit','value')  //this will return the field/measure you want to sum
in your expression:
=sum({.....}$(vMeasure))  //the variable will resolve to the desired measure.

depending on the measure you select, it will use the appropriate field:

edwin_0-1612814791783.png

 

edwin
Master II
Master II

edwin_1-1612814833992.png

 

WojtekSiczek
Contributor
Contributor
Author

Thanks Edwin. It works as expected. 😁

One thing bothers me however. Why my initial if-based approached turned not to be working? Is it a QV bug?

edwin
Master II
Master II

i dont see anything wrong with the expression (although using an if statement in your expression is slower than not using it.)   maybe you can attach your qvw as something else is going on

 

edwin_0-1612879644850.png