Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

changing messure formula dynamically

Hi,

in my Qlik Sense Desktop app I use a messure, whose formula should change depending on the state of a switch (extension "VariableButton"). The switch can be connected to a variable (i.e. vSwitch_on_off). Fortunately it is very easy to change the value of that switch ("on" or "off" / 1 or 0) each other in the field "Button value 1":

=IF(vSwitch_on_off = 0, 1, 0)

Now I want to create a second variable vMessure in my script, whose value would change depending on the state of that switch. This variable could dynamically evaluate in my app calling the syntax $(vMessure).

Anyway, my Problem is: How is the syntax for that part of the script, where I have to assign the formula to the messure variable? I tried this, but without success:

sub create_messure_formula (vSwitch_state)

  if vSwitch_state = 0 then

    vMessure = field1

  else

    vMessure = field2

  endif

end sub

LET vMessure = 'call create_messure_formula (vSwitch_on_off)';


How to get ready? Any help is appreciated!

Thanks and regards!

6 Replies
Gysbert_Wassenaar

Try an expression like: pick($(vSwitch_on_off)+1, field1, field2)


talk is cheap, supply exceeds demand
Not applicable
Author

Thank you for your reply! But maybe I described my actual pattern too simple. In reality I have not only one switch but many, and the formula of the messure needs to include the respective values of all the other switch variables too. So I can not determine the argument for calling the pick function in that moment, without knowing the actual values of the other switches. Is there no possibility for scripting the functional content of that messure outside of that diagram function syntax?

Gysbert_Wassenaar

Perhaps this discussion helps: Re: Using Edit Module Functions in Pivot Table Expression


talk is cheap, supply exceeds demand
Not applicable
Author

Thank you, but to be honest, I don't see, how could this be helpful to me. Is it the easter egg you will recommend to me? Is there such one in Qlik Sense too, but where? Otherwise: If I shall use my switch variables in the way, I call the pick function, unfortunately there seems to be a limitation with the allowed nestings for the IF-function, that I would have to include in my case. In tests I could see, that only a complexity of 9 nesting IFs would work. Actually I would need 12. And on the other hand this syntax structure would not solve all my usability problems, because I need more scripting logics to rule the values of the other switch variables at the same time.

Gysbert_Wassenaar

No, not the easter egg setting. I was thinking of variables containing expressions and nesting these where necessary to build up the logic tree you need. You'd have to do all this in the load script since there's currently not an expression editor for Qlik Sense.


talk is cheap, supply exceeds demand
Not applicable
Author

Ok, that exactly was my point too: I already tried out that in the load script, but found no way in order to assign my complex script logics to the actions, that were triggerd within the sheets. For that in my opinion it will not be sufficient, only to change single variables, because I need to change more than only one variable on one single action.


Therfore could you please make a very simple example, how can I call a sub from a switch (extension "VariableButton") within my sheet, in order to execute several operations? Or is there needed any different approach?


Thanks in advance and best regards!