Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
lwestmaas
Contributor III
Contributor III

Trouble with a variable that evaluates to text

Hello,

I am attempting to insert into a set expression a string value created by a variable that uses a series of if statements based on current selections. I have verified that the variable is properly returning the string, but for some reason I can't then use the string value in a set expression. This is particularly confusing because I have used a variable in set expression before with no issue; however, that variable was an actual string as opposed to an expression that evaluated to a string.

Here is a simplified example of what I'm trying to do. The variable definition is something like:

let clothing = if(count(distinct body_part)=1,if(body_part='Feet','Shoes',if(body_part='Head','Hat')))

If I insert a text box and insert a measure:

$(body_part)

Then select Feet, the box correct displays Shoes (and same for Head).

However, when I use the variable as part of a set expression, nothing is returned. For example, if I write:

count({<[Clothing]={$(clothing)}>} distinct Color)

Nothing is returned.

I've tried a number of adjustments and I'm almost positive the issue is with the variable being evaluated from expression. For example, if I write the actual string in:

count({<[Clothing]={Shoes}>} distinct Color)

it evaluates correctly, and if I set the variable to a string rather than an expression:

set clothing = 'Shoes'

then it also evaluates correctly.

I've tried a number of adjustments, e.g. using text() or putting the variable in quotes, but nothing has worked. Can anyone help?

Thanks!

Lucas

10 Replies
craigsutton
Creator
Creator

I ran into this issue earlier this week.  This might fix it for you. (putting quotes around the $ expansion).

count({<[Clothing]={'$(clothing)'}>} distinct Color)

or

count({<[Clothing]={'=$(clothing)'}>} distinct Color)

OmarBenSalem

I aslo think that Graig's answer is kind of logic; since the $ sign in the variable performs a calculation; and when you calculate a string it will show you null values; so we kind of force it to treat it as a string when surrounding it by quotes.

Capture.PNG

ahaahaaha
Partner - Master
Partner - Master

Hi Lucas,

May be

count({<[Clothing]={Text($(clothing))}>} distinct Color)


Regards,

Andrey

vinieme12
Champion III
Champion III

try

count({<[Clothing]={'$(clothing)'}>} distinct Color)

OR

count({<[Clothing]={'$(=clothing)'}>} distinct Color)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
sasiparupudi1
Master III
Master III

Try

count({<[Clothing]={"$(=clothing)"}>} distinct Color

lwestmaas
Contributor III
Contributor III
Author

Hi Craig,

Thanks for the response - did this work for you? Neither worked for me. Both still return a blank, implying an error. Interestingly, when I use double quotes instead of single quotes, I get a 0 - which implies there's no error even though the output is incorrect.

Lucas

craigsutton
Creator
Creator

Can you change let to set when defining your variable?  You should store the string then evaluate in the set expression.

lwestmaas
Contributor III
Contributor III
Author

This didn't work either. In fact, I just tried an even simpler formula:

count(Clothing=$(clothing))

and nothing was returned, implying an error. I tried this with quotes and with the variable inside a text function but nothing produced a value.

Do you recall your solution?

craigsutton
Creator
Creator

can you change your variable to vClothing.  I am worried that you Clothing field is getting mixed up with your clothing variable.  It is also best practices as I understand it.  I made a test dashboard that might help you figure out what is going wrong.