Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

pedrogomes93
New Contributor II

Variables with parameters

Hello guys,

I have created variables with parameters and they're working as expected, except for when the value has a comma ",".

In this case, commas are used to separate the inputs so how can we bypass this issue ?

Example

Hard coded formula:

  • Avg({< Type= {"2"}, Question = {"Sales / Observe, Listen"} >} Weight) > WORKING

Variable with Parameters

  • QuestionType = Avg({< Type= {"$1"}, Question = {"$2"} >} Weight)
  • $(QuestionType(2, Sales / Observe, Listen)) > NOT WORKING
  • $(QuestionType(2, Sales / Commitment)) > WORKING

Thank you in advance

Tags (2)
1 Solution

Accepted Solutions
felipedl
Valued Contributor III

Re: Variables with parameters

well, I got a workaround working for commas,

First, I added the expression as a variable:

$(teste2(Value,$(testString2)))

Second, I've inputed the testString2 as the string you need, but changed the comma for another character (in my case "|" separator).

Lastly, on the function definition, I used a string replace statment to change the separator, like:

sum({<Teste={"$(=replace($2,'|',','))"}>}$1)

In my screenshot, the last column of the table is the result, getting me the value for the string "Test 1, Test2" after these operations.

sample.png

You'd have to hardcode the needed set analysis types you need, as I stated on my example

9 Replies
felipedl
Valued Contributor III

Re: Variables with parameters

HI Pedro,

Commas work just fine, I believe its the way you set your "function" in the variable, as I understand your passing the types on your second argument to the set analysis.

As an example i used:

data:

Load * Inline

[

Id,Value

1,100

2,333

5,3313

53,111

]

All this expression return values:

1. $(teste(Id,Value))

Expression named "testValue"

2. sum(Value)

3.$(teste(Id,testValue))


sample.png

sample.png

I believe you need to encapsulate your second argument in apostrophes (string like) for it to work the way you need.

pedrogomes93
New Contributor II

Re: Variables with parameters

Hi Felip,

Thank you for your answer.

That is not quite my issue, I understand that the comma is used to separate the fields that I want to use.

My problem is that one of the Field values I want to use as a parameter has a comma: Sales / Observe, Listen

In order to be able to use the variable correctly I need to find a way to have $(QuestionType(2, Sales / Observe, Listen)), in a way that the comma between Observe, Listen is assumed as part of the value and not a separator of the parameters.


Thank you !

agigliotti
Honored Contributor II

Re: Variables with parameters

what about:

QuestionType = Avg({< Type= {"$1"}, Question = {chr(39) & $2 & chr(39)} >} Weight)

?

felipedl
Valued Contributor III

Re: Variables with parameters

well, I got a workaround working for commas,

First, I added the expression as a variable:

$(teste2(Value,$(testString2)))

Second, I've inputed the testString2 as the string you need, but changed the comma for another character (in my case "|" separator).

Lastly, on the function definition, I used a string replace statment to change the separator, like:

sum({<Teste={"$(=replace($2,'|',','))"}>}$1)

In my screenshot, the last column of the table is the result, getting me the value for the string "Test 1, Test2" after these operations.

sample.png

You'd have to hardcode the needed set analysis types you need, as I stated on my example

felipedl
Valued Contributor III

Re: Variables with parameters

The $2 has the commas, and quoting it didn't work on my testing, since it gets only the part of the string before the comma.

Example string: "Test 1, Test2" gets only "Test" as a result since it understands the expansion as two parameters, "Test" and "Test2" ($2 and $3 respectively).

agigliotti
Honored Contributor II

Re: Variables with parameters

let's try replacing comma symbol with chr(44)

felipedl
Valued Contributor III

Re: Variables with parameters

Same story, tested that as well, no luck because its the same situation as I described before.

Re: Variables with parameters

It's a long running problem/limitation that you can't use a comma in the variable parameter value.  It's always interpreted as a parm separator.  The only workaround I've found is to use a proxy character as Felip suggested.

-Rob

pedrogomes93
New Contributor II

Re: Variables with parameters

Hi Felip,

Thank you for your answer

Pedro

Community Browser