Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
bo744
Contributor II
Contributor II

Assigning a list to a variable

Hi everyone!

I'm new to QLIK and I need to use a list of strings in many chart formulas (including some long nested IF statements) and so I want to assign it to a variable if I can. I'm not sure how to do this. 

As an example, this is what I am currently using in one of my charts to exclude products from certain countries in a  dataset - 

Count({$<company_location -= {'U.S.A', 'France', 'Canada', 'U.k.'}>} counts_of_products)

What I would like to do - 

country_list = 'U.S.A', 'France', 'Canada', 'U.k.'

Count({$<company_location -= {country_list}>} counts_of_products)

so that I can reuse the country_list for other charts instead of typing the list every time. Is this possible?

I'd really appreciate any help, thanks!

Labels (5)
1 Solution

Accepted Solutions
lrenwick
Contributor III
Contributor III

Hi

You can create variables by selecting the variable button in edit mode (highlighted below)

lrenwick_0-1670948319418.png

Create new variable vCountryList = {'United States','France','United Kingdom'}

Then it can be used in set analysis as in the example below:

count(distinct
{<
[Country - Placement] =$(vCountryList)
>}PlacementId)

The dollar expansion $ executes the code in the variable to bring back the desired countries

Hope this helps!

View solution in original post

4 Replies
lrenwick
Contributor III
Contributor III

Hi

You can create variables by selecting the variable button in edit mode (highlighted below)

lrenwick_0-1670948319418.png

Create new variable vCountryList = {'United States','France','United Kingdom'}

Then it can be used in set analysis as in the example below:

count(distinct
{<
[Country - Placement] =$(vCountryList)
>}PlacementId)

The dollar expansion $ executes the code in the variable to bring back the desired countries

Hope this helps!

bo744
Contributor II
Contributor II
Author

Hey, thanks for the reply! 

 

When I tried to create the list you said, I get an error -

={'U.S.A','France','Canada'}

Error in expression: '}' expected

 

Any advice with this?

lrenwick
Contributor III
Contributor III

Remove the =

It should look like this in the variable list 🙂

lrenwick_0-1670949495035.png

 

bo744
Contributor II
Contributor II
Author

Works perfectly, thanks a lot! 🙂