Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
joey_lutes
Contributor

Variable Text in Fieldname

I am attempting to insert variable text directly into a fieldname within an expression.

Fieldname Examples:

[KPI AltAvg Parameter]

[KPI AltMax Parameter]

[KPI Avg Parameter]

[KPI Max Parameter]


I have created an inline table:

Load *INLINE [

     Parameter

     AltAvg

     AltMax

     Avg

     Max ];


I've also created a variable called $vParameter that a user can select/set via a selection box.


What I'd like to do is create a measure that looks something like this:

sum('KPI ' & '$(vParameter)' & ' Parameter')


Does this have any chance of working?

Thanks in advance!


1 Solution

Accepted Solutions

Re: Variable Text in Fieldname

How about may be this


Sum($(=$(vParam)))


Or


Sum($(=$(=vParam)))

7 Replies

Re: Variable Text in Fieldname

May be try this:

Sum($(='[KPI ' & vParameter & ' Parameter]'))


Sum($(='[KPI ' & Parameter & ' Parameter]'))

joey_lutes
Contributor

Re: Variable Text in Fieldname

'[KPI ' & $(vParameter1)& ' ' & 'Parameter]'

in a KPI box does indeed create the correct fieldname  = [KPI AltAvg Parameter]

HOWEVER, if I wrap that statement in sum() it breaks.

I have tried creating a Let vParamString = '[KPI ' & $(vParameter1)& ' ' & 'Parameter]' in the loadscript and also in the variable editor (independently).

Unfortunately, the resulting variables don't populate the values and the result of it is the string entered, not the intended variable-created name.

I've also learned that in creating a select box with the Fieldname in it - when I create the associated variable, I simply enter the fieldname in the description.  If I attempt to use GetFieldSelections(Fieldname) it fails (with or without preceding =).  Leaving just the fieldname does populate the variable accordingly when it is selected, however I'm still unable to get it to work properly

I've scoured the net and apparently no one else wants to do this

Other ideas??

Thanks!

Re: Variable Text in Fieldname

I recommended you using the field instead of a variable, did you try this the field Parameter,instead of vParameter?

Sum($(='[KPI ' & Parameter & ' Parameter]'))

joey_lutes
Contributor

Re: Variable Text in Fieldname

Ok, using that concept, I was able to construct the string, as well as create a variable that returns the correct result!!  Almost there.

Now I have:

$vParam = '[KPI' & Parameter & ' ' & 'Parameter]'

so in a KPI box, I can show $(vParam) and it will display

[KPI AltMax Parameter]

Perfect, right!?!

So I got greedy and wrapped a sum() around it.  it said 'no'.

I tried:  sum($(=vParam)) as well.

Since the result of this variable I wanted to be taken to be literal, I'm assuming I'm missing some syntax here?

Re: Variable Text in Fieldname

How about may be this


Sum($(=$(vParam)))


Or


Sum($(=$(=vParam)))

joey_lutes
Contributor

Re: Variable Text in Fieldname

THANK you.  They both actually produced the same, correct result.

I went with the first.  That was a stumper - thanks again!

Re: Variable Text in Fieldname

Awesome. I am glad you were able to make this to work. Always a great feeling.


Best,

Sunny