Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set Analysis - how to use variables inside set analysis

I am a expression like this Sum({<$(vSegment)={'All'}>} Sales) and vSegment contains the field name. This expression is working fine but the showing syntax error at {'All'}.

what is the correct syntax to use variables contains the field names inside set analysis?

Thanks in advance,

Manu

1 Solution

Accepted Solutions
Gysbert_Wassenaar

The syntax of your expression is correct. But the expression editor has some limitations when it comes to checking syntax. For example w.r.t. the dollar expansion of variables on the left side of the = operator. Some expansions can only be done at run time, so they can't be done by the expression editor. The expression editor can't determine that the dollar expansion results in a valid field name. This just means that sometimes you cannot rely on the syntax checker. Sometime you just know better .


talk is cheap, supply exceeds demand

View solution in original post

5 Replies
v_iyyappan
Specialist
Specialist

Hi,

I have to write some example how to use variable using set analysis. please refer it.

Using a variable

4.5.1 Using a variable storing one or several members

Syntax: <Dimension = {$(NameVariable)} >

Or <Dimension = {$(=NameVariable)} >

(with or without the = sign in front of the variable)

Please note that $(=NameVariable) will interpret the variable and therefore QlikView rewrites the

command before executing it.

The content of the variable may contain several members, as if they were in the real syntax. Enclose them

between quotes or bracket according to their name.

Ex :

<MANUFACTURER_LDESC = {$(vChoiceMANUFACTURER)}, CATEGORY_LDESC={$(=ChoiceCategory)}>

There is another $ sign in the set analysis that means the current selection

$(NameVariable): it can be enclosed between double quotes or not like in the example above. If there is

no quote, you may add some in the text of the variable because the member names contain spaces.

4.5.2 Using a variable storing a search string

A normal set: {<MANUFACTURER_LDESC = {"E*"}, CATEGORY_LDESC={"A??”} >}

The variable vChoiceProduit stores a search string and also the double quotes "E*":

{<MANUFACTURER_LDESC = {$(vChoixProduit)}, CATEGORY_LDESC={[A??]} >}

4.5.3 Using a variable storing integer members

With integer keys, you need to enclose the variable name between double quotes:

{<TIME_KEY = {"<$(vFirstPeriod)"}>}

Or {<TIME_KEY = {"<$(=vFirstPeriod)"}>}

The periods between two dates:

{<TIME_KEY = {">$(vFirstPeriod) <$(=vLastPeriod)"} >}

4.5.4 Using a variable storing a dimension

We have already seen that we can use variables with the $ sign. This variable may contain members but

also a dimension:

Ex: sum( {$ <$(vDim)={"*"} >} [Volume Sales])

Because the dimension may contain spaces or specific characters, it would be safer to use the square

brackets (remember that QV rewrites the syntax, so once your dimension name with a space replace the

variable, you would add brackets): sum( {$ <[$(vDim)]={"*"} >} [Volume Sales])

4.5.5 Using a variable storing the whole set

We can store members or dimension into a variable. Why not put the whole syntax?

Ex: sum({$ <$(vSet) >} [Volume Sales])

Ex: sum({$ <$(vSet), CATEGORY_LDESC= "ACC" >} [Ventes Volume])

As you see, we can store the complete syntax or just part of it!

The vSet variable must contain a valid syntax except <> like :

- MANUFACTURER_LDESC ={"*"}, TIME_SDESC={"P 01/13"}

hope its helpful,

regards,

Not applicable
Author

Effectively, you will find all these examples in a document I have published a few days ago:

http://community.qlik.com/docs/DOC-4951

Fabrice

Gysbert_Wassenaar

The syntax of your expression is correct. But the expression editor has some limitations when it comes to checking syntax. For example w.r.t. the dollar expansion of variables on the left side of the = operator. Some expansions can only be done at run time, so they can't be done by the expression editor. The expression editor can't determine that the dollar expansion results in a valid field name. This just means that sometimes you cannot rely on the syntax checker. Sometime you just know better .


talk is cheap, supply exceeds demand
Not applicable
Author

Hi

I have difficult to use set analysis with

variable = variable syntax

example

$(v)={">=$(X)<=$(Y)”}

If it should work, should I insert any value to the variable V in his creation?

Variable X and Y contain a range of values

( Y = Upper limit and X Lower limit)

I get a red marker under the first bracket '}' - (  $(v)={   )

Thanks in advance,

Ariel

Not applicable
Author

Hi Gysbert,

Referring to this discussion, I am using 2 variables to get date range and my expression is : 

= aggr(Sum({WEEKLY<Date = {">=$(=v_CompDt)<=$(=vWeekToDate)"}>} TOTAL_UNITS_SOLD),location)

where v_CompDt is a date field (v_CompDt = max(comp_Date)) (every location is having different Comp_Date) and vWeekToDate is a input-box provided to user (they can select their range).

Scenario : id for Location ABC comp_Date = 10/08/2014 and vWeekToDate = 12/11/2014 (selected by user) so my o/p should range from 10/08/2014 to 12/11/2014 but instead of this it's giving 11/03/2015 to 12/11/2014 (because my variable is max(comp_Date) which is calculating max among all and leading to wrong ans) I tried to solve this by various ways but not getting my ans. Please help me  out with this...

Thanks.

Regrads,

Yojas