Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
IrazaG1A
Contributor
Contributor

Pass in value into a variable for set analysis

I wanted to know if its possible to pass in values from when calling your expression for set analysis. Example

 

vExpression =sum({< Color = {"$1"}>}ACTUAL)

 

vExpression("Blue")

 

What am i doing wrong here? 

Labels (1)
8 Replies
felipedl
Partner - Specialist III
Partner - Specialist III

You'd need to encapsulate the 1 variable into parenthesis like so:

vExpression =sum({< Color = {"$(1)"}>}ACTUAL)

If you have a variable called '1' and a value in it, the $ would expand it to the variable value
IrazaG1A
Contributor
Contributor
Author

I dont have a variable $1 i was using that to hold the value of the first value passed when i called the vExpression variable. So if i just wanted to pass in a value into this expression how should it be. 

vExpression =sum({< Color = {"$(1)"}>}ACTUAL)

marcus_sommer

Try it with:

vExpression:
sum({< Color = {$1}>}ACTUAL)

and then by calling them:
$(vExpression('Blue'))

- Marcus

felipedl
Partner - Specialist III
Partner - Specialist III

Understood what you needed now.

The thing is, to replace the value, you'd have to expand the expression, like so

 

I defined a variable named Expression and value:

sum({< Color = {$1}>}ACTUAL)

 

Next, i've put an expression that gets the following:

$(Expression('a'))

That will expand expression with the parameter 'a', giving me:

sample.png

 

You can from there create "dynamic" set analysis (with the same expression), with expressions like:

$(Expression("1"))

$(Expression("2"))

sample2.png

IrazaG1A
Contributor
Contributor
Author

Thanks so much for getting back to me. Yes it works in Qlikview but iam not sure why iam having an issue doing this in QlikSense. I have used this in Qlikview alot but not sure why in Qlik Sense its giving me issues. exact same formula. Not sure if its anything to do with the way the variable is setup. All of them are setup as SET during load script. 

felipedl
Partner - Specialist III
Partner - Specialist III

That's weird, it works fine on Sense too:

 

sample.png

 

Got it from this script:

Load
date#(Data,'DD/MM/YYYY') as Teste,
*;
load * inline
[
Data,Type,Value
01/01/2019,a,100
02/01/2019,b,200
03/01/2019,c,300
04/01/2019,d,400
05/01/2019,e,500
];

set Expression = sum({< Type = {$1}>}Value);

 

And put as expression the following: $(Expression('a'))

Maybe you're pointing to the wrong field on your expression?

musketeers
Creator
Creator

Hi, What if I want to pass multiple values to color filed. Like I want data for Blue and Red. So I will say:

sum({<color={'red','blue'}>}Actual)

But if I want to pass it dynamically then what is the correct way. The above thread talks about single value to color field in set analysis

marcus_sommer

Within a variable-parameter are commas always treated as a parameter-delimiter without any possibility to mask them. If they are really needed you have 3 workarounds to handle such scenarios:

  • replacing the comma with another unique char within the call and also with the variable-expression
  • using another expression-structure with n parameters
  • avoiding commas by using a different syntax and/or other functions

In your case the last would be the most simple one, for example:

vExpression:
sum({< Color = {$1}>}ACTUAL)

and then by calling them:
$(vExpression((blue|red)))