Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
t_hylander
Creator
Creator

set a variable depending on a diffrent variables content

Hi

Not sure how to solve this, so not sure how to search for an answer.

Ive got several buttons, that sets a variable as a action. Button1 sets vProduct='Cars', Button2 sets vProduct='Boats' asf.

Now I want a bar chart to dynamic show the number of Products with a reclamation (I set a flag when loading the data).

date_RecFlagCars_RecFlagBoats
2017-06-0110
2017-06-0210
2017-06-0401
2017-06-0400
2017-06-0601

When Button1 is pressed the barchart should only show 'sum(_RecFlagCars)' (with date as dimension).

Id like to use the variable that I use on the Button1 to change the ending om '_RecFlag', something like this;

"Sum({<Week={=$(vCurrWeek)}>} _RecFlag" & vProduct & "')"

I've tried using a inline-table like this;

Value, expression

Cars, Sum({<Week={=$(vCurrWeek)}>} _RecFlagCars)

Boats, Sum({<Week={=$(vCurrWeek)}>} _RecFlagBoats)

But when I look at expression it shows "Sum({<Week={}>} _RecFlagCars", of some reason it dont like the variable in there

Does anyone have any idea how to solve this?

1 Solution

Accepted Solutions
YoussefBelloum
Champion
Champion

No, I mean on the barcharts when trying to change the expression between _RecFlagCars and _RecFlagBoats.


If($(vProduct)='Cars', Sum({<Week={=$(vCurrWeek)}>} _RecFlagCars ), Sum({<Week={=$(vCurrWeek)}>} _RecFlagBoats) )

View solution in original post

6 Replies
YoussefBelloum
Champion
Champion

Hi,

why don't you simply use an If to solve this ?

t_hylander
Creator
Creator
Author

You mean on the buttons when I assigning the variable?

YoussefBelloum
Champion
Champion

No, I mean on the barcharts when trying to change the expression between _RecFlagCars and _RecFlagBoats.


If($(vProduct)='Cars', Sum({<Week={=$(vCurrWeek)}>} _RecFlagCars ), Sum({<Week={=$(vCurrWeek)}>} _RecFlagBoats) )

jonathandienst
Partner - Champion III
Partner - Champion III

The problem is that the $ expansion is happening inside the inline load, so it is attempting to substitute $(vCurrWeek) with the value of vCurrWeek - which is probably undefined at that point. If you load from a text file or spreadsheet, the $ expansion will not take place. In an inline, you will need to delay the expansion. This is one way

LOAD

  Value,

  Replace(expression, '#', '$') as expression

Inline

[

Value, expression

Cars, Sum({<Week={=#vCurrWeek)}>} _RecFlagCars)

Boats, Sum({<Week={=#(vCurrWeek)}>} _RecFlagBoats)

];

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
t_hylander
Creator
Creator
Author

ofcourse, stupid me. Works like a charm!

t_hylander
Creator
Creator
Author

This work to, but with the IF-statement theres no need for a inline-load.

Could be useful in other scenarios aswell so Ill keep it in mind.

Thanks!