Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
hlines_usacs
Creator II
Creator II

Set Analysis with Set Modifiers and Variables

Hello,

I am trying to use Set Modifiers within Set Analysis by using a variable. Very similar to the "Set Modifiers" portion of this thread. Set Analysis

Using the example below, I want to have 'West coast' and 'South America' replaced with a variable.

sum( <[Sales Region]={'West coast', 'South America'}>} sales)

where $(vExampleVariable) = 'West coast', 'South America' I want to use the following:

sum( {<[Sales Region]={$(vExampleVariable)}>} sales)


I have tried many different ways of writing the set analysis but can't seem to get the correct syntax.

1 Solution

Accepted Solutions
Anonymous
Not applicable

It is about Qlik Sense...
There is no variable support in Qlik Sense the same as in QlikView.  You need extensions to use variables on the front end.  I assume the problem here is the limitation of the extension.

So, instead of using a variable here, the full variable definition should be used in set:

sum( {<[Sales Region]={$(=chr(34) & concat(distinct [Field Name], chr(34)&','&chr(34)) & chr(34))}>} sales)

Tested, worked for me.

View solution in original post

16 Replies
Anonymous
Not applicable

I don't see anything wrong with your last expression syntax.  But the definition of the variable is not clear.  I'd expect

vExampleVariable = 'West coast', 'South America'

To test - what you see in a text box with expression =vExampleVariable ?

maxgro
MVP
MVP

in the script set the variable

SET vExampleVariable = 'West coast', 'South America';

and the expression is

sum( {<[Sales Region]={$(vExampleVariable)}>} sales)

Not applicable

Hello Hanna,

I tried reproducing your situation and I think your error is in the definition of the variable, the comma should be included in the apostrophes:

$(vExampleVariable) = 'West coast, South America'

hlines_usacs
Creator II
Creator II
Author

The variable is not created in the script. I created the variable while editing the sheet.

The definition of the variable is Concat(DISTINCT [Field Name],',')

I have tried the following and none work properly.

Concat(DISTINCT [Field Name], ',')

Concat(DISTINCT '"'&[Field Name]&'"', ',')

Concat(DISTINCT [Field Name], ',')

Concat(DISTINCT chr(39)&[Field Name]&chr(39), ',')


I have a text box that shows me the value of $(vExampleVariable).

When I just put vExampleVariable in a text box, it does not return anything.

hlines_usacs
Creator II
Creator II
Author

I tried this also, and it did not work.

Anonymous
Not applicable

Try this

=chr(34) & concat(distinct [Field Name], chr(34)&','&chr(34)) & chr(34)

hlines_usacs
Creator II
Creator II
Author

That did not work either.

Anonymous
Not applicable

I just tried it with QlikView 12:.

LOAD * INLINE [
Region, Value
West coast, 1
South America, 2
Europe, 34
]
;


Textbox:

=sum({<Region ={$(var)}>} Value )

No problems:

Variable Overview:

sunny_talwar

Try with Chr(39) instead of Chr(34)

=Chr(39) & Concat(DISTINCT [Field Name], Chr(39) & ',' & Chr(39)) & Chr(39)