Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Highlighted
t_hylander
Contributor

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?

Tags (2)
1 Solution

Accepted Solutions
YoussefBelloum
Esteemed Contributor

Re: set a variable depending on a diffrent variables content

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) )

6 Replies
YoussefBelloum
Esteemed Contributor

Re: set a variable depending on a diffrent variables content

Hi,

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

t_hylander
Contributor

Re: set a variable depending on a diffrent variables content

You mean on the buttons when I assigning the variable?

YoussefBelloum
Esteemed Contributor

Re: set a variable depending on a diffrent variables content

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) )

MVP
MVP

Re: set a variable depending on a diffrent variables content

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
Contributor

Re: set a variable depending on a diffrent variables content

ofcourse, stupid me. Works like a charm!

t_hylander
Contributor

Re: set a variable depending on a diffrent variables content

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!