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: 
Anonymous
Not applicable

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

1 Solution

Accepted Solutions
felipedl
Partner - Specialist III
Partner - Specialist III

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

View solution in original post

9 Replies
felipedl
Partner - Specialist III
Partner - Specialist III

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.

Anonymous
Not applicable
Author

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
Partner - Champion
Partner - Champion

what about:

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

?

felipedl
Partner - Specialist III
Partner - Specialist III

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
Partner - Specialist III
Partner - Specialist III

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
Partner - Champion
Partner - Champion

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

felipedl
Partner - Specialist III
Partner - Specialist III

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

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

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

Anonymous
Not applicable
Author

Hi Felip,

Thank you for your answer

Pedro