Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Talk to Experts, a LIVE Q&A Webinar. Bring your Qlik Sense Business questions on Aug. 4th. Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
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
Highlighted
Creator
Creator

Re: Trouble with a variable that evaluates to text

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)

Highlighted
Partner
Partner

Re: Trouble with a variable that evaluates to text

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

Highlighted
Master
Master

Re: Trouble with a variable that evaluates to text

Hi Lucas,

May be

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


Regards,

Andrey

Champion II
Champion II

Re: Trouble with a variable that evaluates to text

try

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

OR

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

Highlighted
Master III
Master III

Re: Trouble with a variable that evaluates to text

Try

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

Highlighted
Contributor III
Contributor III

Re: Trouble with a variable that evaluates to text

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

Highlighted
Creator
Creator

Re: Trouble with a variable that evaluates to text

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

Highlighted
Contributor III
Contributor III

Re: Trouble with a variable that evaluates to text

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?

Highlighted
Creator
Creator

Re: Trouble with a variable that evaluates to text

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.