Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Gaël
Contributor III
Contributor III

Clear a variable when another variable's value changes

In the beginning, all was simple. I have a graph of Count(Orders) over time.

I have a set of 8 categorical variables that all could be used to filter the data and/or to produce a stacked surface or bar chart, but some have many categories and the chart wouldn't be readable. My goal therefore to highlight only one category of one variable at a time, while still being able to filter on other variables. I thus display two data series: highlighted + rest. This works - but just nearly.

Gal_2-1716481047055.png

I figured I could use two variables v.HighlightField and v.HighlightValue. The first series would display Count({$<[$(v.HighlightField)]={'$(v.HighlightValue)'}>} Orders), the other one the rest.

I use a first VizLib Variable Input to set v.HighlightField, and a second one to set v.HighlightValue. [If you're curious: it's dynamic values are defined as: Pick(Match(v.HighlightField, '', [Field name 1], [Field name 2], ...), [Value list 1], [Value list 2], ...)]

Now when I set a value of v.HighlightField and a value of v.HighlightValue in the dropdown boxes and subsequently change the v.HighlightField, the value of v.HighlightValue stays as it is. I end up with an incompatible combination of field and value.

Gal_0-1716478344708.png

How do I clear the latter variable when the former changes? This would do the trick.
Or maybe you know a completely different solution? One big variable with all field names and all values? Meh. Dummy fields to use in the set expression?

PS: Even if it might work, the big-variable solution is not appealing (the list has 43 lines):

Gal_0-1716497120720.png

 

Labels (2)
1 Reply
Gaël
Contributor III
Contributor III
Author

PS: A slight, yet imperfect improvement over the above is defining three variables in the DataModel as follows and use them in the 'dynamic values' section of the 'Vizlib variable input' dialogs as well as a conditional legend of the graph:

// dimensions
Set v.FilterVariables='|Agent type|Creation process|...';
Let v.FilterVariables2=Chr(39)&Replace(v.FilterVariables, '|', Chr(39)&', '&Chr(39))&Chr(39);

// List of list of values of the relevant variables
// to be used as 'dynamic values' in a VizLib Variable Input
// Quick & Dirty solution - obviously, it would be good to extract this information from the data
Set v.FilterVariableValues=
'',
'|Company|HCProvider|Institution|Laboratory|Person',
'|HL7|Human',
...;

Then the first Variable Input setting sets v.HighlightCategory takes as input
=v.FilterVariables
The second Variable Input setting v.HighlightValue takes as input:
=Pick(Match(v.HighlightCategory, $(v.FilterVariables2)), $(v.FilterVariableValues))
The graph legend of the highlighted item is:
=If(Index(Pick(Match(v.HighlightCategory, $(v.FilterVariables2)), $(v.FilterVariableValues)), v.HighlightValue), v.HighlightCategory & ': ' & v.HighlightValue)

With this way of doing, the remaining headache is how to dynamically populate v.FilterVariableValues in the script. Then again, there may be a totally different and much simpler method to achieve the same.