
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- « Previous Replies
-
- 1
- 2
- Next Replies »
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello
did you try
$(=vMonth)
?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why don't you try just this
Sum({<Date = p(Months)>}sales)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Sunny. Either GetFieldSelections or Concat expression work, now I am trying to make the variable method working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Robin. I did, but no luck here.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
But p() doesn't work?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- « Previous Replies
-
- 1
- 2
- Next Replies »