Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
bekahbeets
Creator
Creator

set analysis formula comparable to sql's 'in' command?

I have set a variable equal to a field selection like so:

vSelectedYear = GetFieldSelections(YearField)

sometimes vSelectedYear will hold multiple values (2017, 2016, etc)

The set analysis formula looks like such right now:

sum(  {<YearField = {"$(=$(vSelectedYear))"} >}  [$(vType)])

this works fine if only one year is selected, but I would like it to work when vSelectedYear holds multiple years.

In Sql it would look like:

Select sum(vType)

from table

where YearField in (vSelectedYear)

Labels (1)
1 Solution

Accepted Solutions
swuehl
Champion III
Champion III

It should work if you remove the double quotes (assuming integer values for years):

sum(  {<YearField = {$(=$(vSelectedYear))} >}  [$(vType)])


Or use the p() function or the scope operator to directly acces field values selected or possible:

sum(  {<YearField = $::YearField >}  [$(vType)])


sum(  {<YearField = p(YearField) >}  [$(vType)])


(though latter set expression should not make a difference to just the pure aggregation?)

View solution in original post

2 Replies
swuehl
Champion III
Champion III

It should work if you remove the double quotes (assuming integer values for years):

sum(  {<YearField = {$(=$(vSelectedYear))} >}  [$(vType)])


Or use the p() function or the scope operator to directly acces field values selected or possible:

sum(  {<YearField = $::YearField >}  [$(vType)])


sum(  {<YearField = p(YearField) >}  [$(vType)])


(though latter set expression should not make a difference to just the pure aggregation?)

bekahbeets
Creator
Creator
Author

Thanks! Removing the quotes did the trick!