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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
nicanova
Luminary
Luminary

Nesting Variables

Hi - I'm trying to figure out if I can nest Variables using Variable input. I've been asked to set up 2 ways of characterizing our sales opportunities, reflected in a bar chart. So I set up a Variable Input with 2 buttons that does a different set analysis based on the choice, 'Standard' and 'Non-Standard', and this is working perfectly.

vOld - Variable input with 2 buttons:

Standard: sum({$<[10 Yr Flag]={'Y'},Type={'Old'}>} [Total Contract Value])

Non-Standard: sum({$<[10 Yr Flag]={'Y'},Type={'Old'}>} [Total Contract Value])+sum({$<[10 Yr Flag]={'Y'},[Non-StandardFlag]={1}>} [Total Contract Value])

On top of that, I want to layer the fact that we have 2 ways of calculating our totals: Total Contract Value and a Factored Total. I tried setting another Variable input $(vTCV) with a choice of TCV or Factored amounts, which works on its own, but if I try to incorporate $(vTCV) into the Standard/Non-Standard expressions by replacing [Total Contract Value], I get an error that 'it contains only undefined values'.

vTCV - Variable input with 2 buttons:

TCV: [Total Contract Value]

Factored: [Factored TCV]

The bar chart measure is just: $(vOld)

Worst case, I will just consolidate into one Variable Input with 4 buttons: StandardTCV, StandardfTCV, NonStandardTCV, NonStandardfTCV

thanks in advance!

Labels (3)
1 Solution

Accepted Solutions
marcus_sommer
MVP
MVP

Nesting of variables is a rather bad idea. Of course, it's technically possible but it has various restrictions in regard to the syntax by creating and calling each part of it - and very important each comma within such variable-part is treated as parameter-delimiter.

Quite often creates such an approach a lot of efforts and a high complexity - without providing a general solution for similar cases else it's each time handwork ...

- Marcus

View solution in original post

4 Replies
brunobertels
Master
Master

Hi 

I do this in one of my app 

English is'nt ma native language so i'wiil try to explain

So you have a variable with 2 button each of it as a différent mesure  based one [Total Contract Value] dimension 

then you want to add a variable button that allow to swap the dim between  [Total Contract Value] and [Factored TCV]

So create a variable 

vTCV

 

add value 1 ( for [Total Contract Value] )

Value 2 for [Factored TCV]

 

create a variable in the panel editor let say vTCV1 and add this mesure 

=pick($(vTCV),'[Total Contract Value]','[Factored TCV]')

 

then now in your variable vOld  change the mesure like this 

Standard: sum({$<[10 Yr Flag]={'Y'},Type={'Old'}>} $(vTCV1))

Non-Standard: sum({$<[10 Yr Flag]={'Y'},Type={'Old'}>} [Total Contract Value])+sum({$<[10 Yr Flag]={'Y'},[Non-StandardFlag]={1}>} $(vTCV1))

 

If i understodd well your desired output and if i did not make mistake by replacinh my own variable name by ours 

it may work fine .. 

 

below an example with a simple graph aned this logic that allow me to swap between Time dimension Day Week Month 

and 3 kind of dimension in my mesure ( Received , Offered , HAndled calls ) 

brunobertels_0-1668791495727.png

 

nicanova
Luminary
Luminary
Author

Hi - Thank you! I tried, but it isn't working:

vTCVPick: =pick($(vTCV),'[Total Contract Value]','[Factored TCV]')

Standard: sum({$<[10 Yr Flag]={'Y'},Type={'Old'}>} $(vTCVPick))

     Error in expression: Sum takes 1 parameter

 

Picture of vTCV Values:

nicanova_0-1668793918910.png

Result:

nicanova_1-1668793926278.png

 

 

marcus_sommer
MVP
MVP

Nesting of variables is a rather bad idea. Of course, it's technically possible but it has various restrictions in regard to the syntax by creating and calling each part of it - and very important each comma within such variable-part is treated as parameter-delimiter.

Quite often creates such an approach a lot of efforts and a high complexity - without providing a general solution for similar cases else it's each time handwork ...

- Marcus

brunobertels
Master
Master

Hi 

See attached qvf example with a step by step example 

 

Hope it helps