Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Talk to Experts, a LIVE Q&A Webinar. Bring your Qlik Sense Business questions on Aug. 4th. Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor III
Contributor III

Variable in variable

Hello,

I have a problem with using variable in another variable.

I use number slider from 1 to 6 (step by 1), which changing variable 'vHour' - so it is number.

Then I have the second (text) variable 'vPeriod', which is name of flag in load script.

I use set analyse with this flag, so I need change set analyse by text variable.

This code does not work: [flag&text($(vHour))&hours]

Load script for flags:

if(now()-num(eventdtcr) < 0.25,'1','0') as flag6hours,

    if(now()-num(eventdtcr) < 0.2083,'1','0') as flag5hours,

    if(now()-num(eventdtcr) < 0.1666,'1','0') as flag4hours,

    if(now()-num(eventdtcr) < 0.125,'1','0') as flag3hours,

    if(now()-num(eventdtcr) < 0.0833,'1','0') as flag2hours,

    if(now()-num(eventdtcr) < 0.0416,'1','0') as flag1hours...

Set analyse: if(len(text(avg({$<$(vPeriod)={'1'}>} flagEPA))) = 0,'NO EVENT SCAN',avg({$<$(vPeriod)={'1'}>} flagEPA))

Next idea: '[flag' & text($(vHour)) & 'hours]' does not work too...

Thank you for your's answers.


1 Solution

Accepted Solutions
Highlighted
Contributor III
Contributor III

Re: Variable in variable

Hi, I solved it.

As variable:

vVariale: text('avg({$<[flag' & text($(vHour)) & 'hours]={''1''}>} flagEPA)')

measure: ...$(=$(vVariable)) ...

View solution in original post

8 Replies
MVP & Luminary
MVP & Luminary

Re: Variable in variable

I think by using this: '[flag' & text($(vHour)) & 'hours]' the following call should work:

if(len(text(avg({$<$(=vPeriod)={'1'}>} flagEPA))) = 0,'NO EVENT SCAN',avg({$<$(=vPeriod)={'1'}>} flagEPA))

Whereby I would probably use only one flag like:

hour(now()-eventdtcr) -1 as Flag

and as expression something like this:

alt(avg({$<Flag={$(vHour)}>} flagEPA), 'NO EVENT SCAN')

- Marcus

Highlighted
Contributor III
Contributor III

Re: Variable in variable

Your code does not work...

Now I try this code: '[flag' & text($(vHour)) & 'hours] ={'1'}' , but I have a problem with apostrofs in braces

Any ideas?

Highlighted
Specialist II
Specialist II

Re: Variable in variable

share some sample data

Highlighted
MVP & Luminary
MVP & Luminary

Re: Variable in variable

Do you mean you don't want just create the field for the set analysis else the complete set analysis statement? Then of course you would need to handle multiple quotings and here probably by doubling the quotes like ...{''1''} ... But I would use string-values in such cases else really using the pure number like ... {1} ... and of course creating the flags in this way too.

- Marcus

Highlighted
Contributor III
Contributor III

Re: Variable in variable

Yeah, I changed it by if(len(text(avg({$<$(vPeriod)>} flagEPA))) = 0,'NO EVENT SCAN',avg({$<$(vPeriod)>} flagEPA))


and vPeriod = 'flag' & text($(vHour)) & 'hours={''1''}'


but still does not work ...

Highlighted
MVP & Luminary
MVP & Luminary

Re: Variable in variable

Your variable needs to be evaluated before it's result is applied as set analysis statement with a $-sign expansion like above already mentioned - this meant: $(=vPeriod)

- Marcus

Highlighted
Specialist II
Specialist II

Re: Variable in variable

Instead of making 6 flag columns, why not a single flagHour that contains 1 - 6 then you are changing the right side (as opposed to left) of the equation.

Highlighted
Contributor III
Contributor III

Re: Variable in variable

Hi, I solved it.

As variable:

vVariale: text('avg({$<[flag' & text($(vHour)) & 'hours]={''1''}>} flagEPA)')

measure: ...$(=$(vVariable)) ...

View solution in original post