Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
fe-c
Contributor III
Contributor III

Parameterized Visualization by Variable Input Field (drop-down)

Hi,
I'm currently struggling with 'parameterized boxplot'. I would like to create dynamically generated boxplots based on variable input fields (drop down) by the user. Normally that works well but now I want combine a seccond variable for a special case. 
 
So I defined a flag value ('compVal') in the drop down for the dimension variable but it's not working properly. I think I have some misundertstanding how Qlik handles $(strings/variables) in general but can't identify it.
 
So here is, what I've tested so far (pseudo-code):
set dimX_var1 = 'val_of_var1';
set dimX_var2 = 'val_of_var2';
 
Boxplot without '=if(…':
=$(='$(dimX_var1)') --> val_of_var1   --> editor: OK --> run
='$(dimX_var1)'     --> 'val_of_var1' --> editor: OK --> run
=$(dimX_var1)       --> val_of_var1   --> editor: OK --> run

=$(='$(dimX_var2)') --> val_of_var2   --> editor: OK --> run
='$(dimX_var2)'     --> 'val_of_var2' --> editor: OK --> run
=$(dimX_var2)       --> val_of_var2   --> editor: OK --> run
 
So every 'version' is working fine. I think Qlik handles my clueless definition of dimension by variables in the background. 
 
Boxplot with simple '=if(…':
=if(true(),$(='$(dimX_var1)')) --> if(true(),val_of_var1)   --> runI 
=if(true(),'$(dimX_var1)')     --> if(true(),'val_of_var1') --> fail
=if(true(),$(dimX_var1))       --> if(true(),val_of_var1)   --> run

=if(true(),$(='$(dimX_var2)')) --> if(true(),val_of_var2)   --> run
=if(true(),'$(dimX_var2)')     --> if(true(),'val_of_var2') --> fail
=if(true(),$(dimX_var2))       --> if(true(),val_of_var2)   --> run
I don't get it completly in comparision with my first tests, but behavior is consistent for me so far.
 
Next step is the real case distinction
 
Boxplot with '=if(…':
=if(match('$(dimX_var1)','comp_val')=1
    ,$(='$(dimX_var2)')
    ,$(='$(dimX_var1)')
    )
    
--> if(match('val_of_var1','comp_val')=1,val_of_var2,val_of_var1)
--> if true  --> editor: fail --> run
--> if false --> editor: Ok   --> fail
editor: Error because 'val_of_var1' is no valid dimension, but it works because true-condition is ok
 
Next try:
=if(match('$(dimX_var1)','comp_val')=1
    ,'$(dimX_var2)'
    ,'$(dimX_var1)'
    )
    
--> if(match('val_of_var1','comp_val')=1,'val_of_var2','val_of_var1')
--> if true  --> editor: OK --> fail
--> if false --> editor: OK --> fail
Ok, behavior like 'simple if(true())'-test and comprehensible.
 
Next version:
=if(match('$(dimX_var1)','comp_val')=1
    ,$(dimX_var2)
    ,$(dimX_var1)
    )
    
--> if(match('val_of_var1','comp_val')=1,val_of_var2,val_of_var1)
--> if true  --> editor: Error --> run
--> if false --> editor: OK    --> fail
Still don't get it, like $(='$(…)') in comparision with boxplot test without if() statement.
 
Mixed version:
=if(match('$(dimX_var1)','comp_val')=1
    ,$(dimX_var2)
    ,'$(dimX_var1)'
    )
    
--> if(match('val_of_var1','comp_val')=1,val_of_var2,'val_of_var1')
--> if true  --> editor: Ok --> run
--> if false --> editor: OK --> run but wrong
Instead of multiple boxes based on 'val_of_var1'-dimension (e.g. dimension = collection, values only 'new' & 'old') I get only a single box callld by the name of dimension (here: collection).
 
Ok, the last mixed version is nonsense, but why isn't the $(='$(…)')-version running as aspected?
Labels (5)
4 Replies
marcus_sommer

A field-reference mustn't be a 'string'. Therefore you may try for the calculated dimension:

if(match([$(dimX_var1)],'comp_val'),[$(dimX_var2)], [$(dimX_var1)])

 

fe-c
Contributor III
Contributor III
Author

Hi Marcus, 

thanks for reply. I tried "all" variations with '['-brackets but nothing worked properly. Can you explain the difference or what should happen?

A (half) solution is referencing to dimX_var2 as a possible (drop-down) value for dimX_var1.

='$(dimX_var2)'

Then I can define the dimension with

=$(dimX_var1)

and the boxplot run like expected.

Why this is only half the way shows up, when I change the value of dimX_var2 (e.g. change weight from kilogram to milligram). Then my drop-down field of dimX_var1 empties. If I select the value in dimX_var1 again I get the correct visualisation with updated dimX_var2.

So if there was a way to auto-update dimX_var1 after changing dimX_var2 (no extra button/click), my problem would be solved.

marcus_sommer

The [] brackets respectively appropriate "" quotes are only mandatory if the field-name contained spaces or any kind of special chars - otherwise the may be skipped. If the variable-values itself are created with brackets/quotes the call of the variable mustn't be within brackets/quotes.

In some way is the variable-handling quite easy because the resolved result of a variable must only look as if the wanted content has be directly written. Therefore the simplest approach is often creating the target-object without a variable - adding quite normal the dimensions + expressions. If this is working as expected those parts which should be dynamically are replaced step by step. Because of the fact that the origin working has been proved each afterwards difference has the cause that the variable has the wrong value respectively is called with a not suitable syntax. In many scenarios it's only a matter of a few attempts to find the working ones - and I suggest to start such things always with a table-chart which has nearly no struggles to object-properties like axis and so on and enables more possibilities to add some more dimensions + expressions in parallel as the graphic-charts.

Beside of this the variable-handling could become quite tricky because there are dependencies between the ways how the variable is created (immediately evaluated or for a later evaluation) and where they is called (dimension, expression, variable, any property) again and which kind of content (string, number, field-reference, expression, variable) they have.

Apart from the above you may simplify your task by unifying the units and/or reflecting them within the expressions or the formatting.

fe-c
Contributor III
Contributor III
Author

Thanks for the explanation!

Ok, then "[" is not a problem/solution for my misunderstanding because I prefer the old fashioned way of forbidden (special) characters or blanks in names, paths, variables etc.

I also prefer to define as much as possible in the script for better maintanance. Experience to date has shown that the number of visualizations increases 'magically' due to user requests. The effort required to implement these requests while retaining the look&feel or corporate identity grows exponential. I think you know what I mean.

Normally I work/test with tables as you recommend. I don't understand why my formula doesn't work properly, but the (imperfect) half-solution will have to “do” for now.