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: 
GrantBooth
Creator
Creator

Multiple Values for Variable

Repost because I wasn't clear enough.

I'm trying to use multiple values for an variable within an expression and I can't quite get the syntax right.

I have variable v.Example (obviously I am using proxies as I can't show my details)

Sum({< Category1 = {"$1"},
              Category2 = {"$2"}>}
Amount)/1000))

Category1 can take the following values up, down, left, right

Category2 can take the following values peppermint, topspin, Cthulu - 

So within an expression, if I'm looking for say Category1 to be down, and Category2 to be Cthulu, I would now write

$(v.Example(down, Cthulu))

I would like to be able to select more than value for each variable in my set expression so for example I would like

$(v.Example(down, [peppermint, Cthulu]))

Can someone please help out with the correct syntax? 

Cheers

1 Solution

Accepted Solutions
RsQK
Creator II
Creator II

Hey!

This may work for you:

So you create a variable like this (the idea will be the same for other categories/dimensions):

Sum({<Category2*={$(=CHR(34) & CONCAT(REPLACE('$1',';',CHR(34) & ',' & CHR(34)),',') & CHR(34))}>}Amount)/1000

 And you call the variable like this:

$(v.Example(Cthulu;peppermint))

View solution in original post

7 Replies
vikasmahajan

Hi,

community.qlik.com/t5/New-to-Qlik-Sense/Pass-in-value-into-a-variable-for-set-analysis/td-p/1590111

&

https://community.qlik.com/t5/QlikView-App-Dev/Passing-parameters-to-set-analysis-expression-called-...

hope this helps you

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
GrantBooth
Creator
Creator
Author

Thank you, I'm really keen to know if there's a simple solution though, is it possible to enter two different parameter values into a variable, and if so how? As a reminder, I'm looking for something like this

$(v.Example(down, [peppermint, Cthulu]))

 

 

 

RsQK
Creator II
Creator II

Hey!

This may work for you:

So you create a variable like this (the idea will be the same for other categories/dimensions):

Sum({<Category2*={$(=CHR(34) & CONCAT(REPLACE('$1',';',CHR(34) & ',' & CHR(34)),',') & CHR(34))}>}Amount)/1000

 And you call the variable like this:

$(v.Example(Cthulu;peppermint))
marcus_sommer

Your variable-parameter mustn't have an included comma because the comma is parameter-delimiter and each comma within a $-sign expansion will be treated as a separate parameter. AFAIK there is no way to mask these logic.

Possible are replace-logics but they could become more complicated as they are helpful. Probably there are very rare scenarios in which it could be practically to implement such approaches.

Beside this you could apply syntax which doesn't need commas - by multiple values for a field you may specify them as:

(value1|value2|value3)

- Marcus

GrantBooth
Creator
Creator
Author

Thanks, that works perfectly

RsQK
Creator II
Creator II

@marcus_sommer , if i understood correctly:

Define a variable like this:

SUM({<$(=REPLACE('$1;$2;$3;$4;$5;$6',';',','))>}sales)

Call it like this:

RsQK_0-1639552216797.png

Inside expression editor it looks like this:

RsQK_1-1639552261043.png

Meaning three values were passed as one for the $1.

marcus_sommer

Yes, you could do it in this case in this way and it looked here not too complicated. But you need to add an extra logic to resolve your bypass-measures and keeping in mind that you will apply a different value-concat syntax as the Qlik native ones.

Quite often are the scenarios more complex and the values may contain spaces and/or special chars and/or may contain also this delimiter-char and/or aren't  complete values else search-strings. Also the variable-parameter-logic may not only be used to specify values else also for (parts of) fieldnames, multiple conditions, operators/identifiers/modifiers or functions. Further not seldom are the users trying to nest multiple variables.

In general everything from the above mentioned stuff is technically solvable but the complexity and the efforts to get this all right - beside the comma-topic also the entire quotes-sysntax-stuff - could become extremely high. Therefore my suggestion to keep the things simple and not adding extra logics else switching to comma-avoiding syntaxes and also to consider if the variable-stuff really simplified the life or if it starts to tends to the opposite ...  

- Marcus