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: 
yzhang88
Contributor III
Contributor III

Using variable in set analysis

Hi all,

I am trying to store the selected values in a variable, then use the variable in set analysis.

Method 1:

step1: create variable vMonth=GetFieldSelections(Months in List box),

step2: in set analysis expression, I use =sum({<Date={"$(vMonth)"}>}sales);

Method 2:

step1: create variable vMonth==concat(distinct (Months in List box), chr(39)&', '&chr(39)),

step2: in set analysis expression, =sum({<Date={'$(vMonth)'}>}sales);

Neither of these two methods don't work with variables. If I use GetFieldSelection or Concat directly in set analysis expression , both are working.

=sum({<Date={"$(=GetFieldSelections(Months in List box))"}>}sales)

=sum({<Date={'$(=concat(distinct (Months in List box), chr(39)&', '&chr(39)))'}>}sales)

Not sure if I miss anything, any suggestions? Thx.

1 Solution

Accepted Solutions
yzhang88
Contributor III
Contributor III
Author

Just figure out this issue. I am defining different alternate states in each sheet, so need put state name when creating variables.

Method 1:

step1: create variable vMonth=GetFieldSelections(Months, ',', 100, 'StateName'),

step2: in set analysis expression, I use =sum({<Date={"$(vMonth)"}>}sales);

Method 2:

step1: create variable vMonth=concat({[AlternateStateName]}distinct (Months in List box), chr(39)&', '&chr(39)),

step2: in set analysis expression, =sum({<Date={'$(vMonth)'}>}sales);

both $(vMonth) or $(=vMonth) working.


Thanks everyone.


View solution in original post

12 Replies
olivierrobin
Specialist III
Specialist III

hello

did you try

$(=vMonth)

?

sunny_talwar

Why don't you try just this

Sum({<Date = p(Months)>}sales)

yzhang88
Contributor III
Contributor III
Author

Thanks Sunny. Either GetFieldSelections or Concat expression work, now I am trying to make the variable method working.

yzhang88
Contributor III
Contributor III
Author

Thank you Robin. I did, but no luck here.

sunny_talwar

But p() doesn't work?

shansundar
Partner - Creator
Partner - Creator

Hi,

You have to use both concat and get field selections.

Because when multiple values are selected values will be displayed like A,B we need make it 'A','B' as the variable result.

Thanks,

Shan S

yzhang88
Contributor III
Contributor III
Author

Hi Sunny, I didn't try, it might work. My focus on this question is trying to make the variable method working, not find workaround solution The P() function might work, in my post, using GetFieldSelections or Concat directly in set analysis expression also work. I am new to Qlik and try to learn more stuff during projects. Thx.

sunny_talwar

yzhang88‌ - you are free to try and learn, but p() is not a work around.... what you are trying is work around and that too longer work around which I would recommend not using over p().... If I were new, I would first learn p() and then go onto learning other ways of doing it

yzhang88
Contributor III
Contributor III
Author

Just figure out this issue. I am defining different alternate states in each sheet, so need put state name when creating variables.

Method 1:

step1: create variable vMonth=GetFieldSelections(Months, ',', 100, 'StateName'),

step2: in set analysis expression, I use =sum({<Date={"$(vMonth)"}>}sales);

Method 2:

step1: create variable vMonth=concat({[AlternateStateName]}distinct (Months in List box), chr(39)&', '&chr(39)),

step2: in set analysis expression, =sum({<Date={'$(vMonth)'}>}sales);

both $(vMonth) or $(=vMonth) working.


Thanks everyone.