Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Anonymous
Not applicable
Author

Hi, I solved it.

As variable:

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

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

View solution in original post

8 Replies
marcus_sommer

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

Anonymous
Not applicable
Author

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?

techvarun
Specialist II
Specialist II

share some sample data

marcus_sommer

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

Anonymous
Not applicable
Author

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 ...

marcus_sommer

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

dwforest
Specialist II
Specialist II

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.

Anonymous
Not applicable
Author

Hi, I solved it.

As variable:

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

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