Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
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

SET vClothing = =if(count(distinct body_part)=1,if(body_part='Feet','Shoes',if(body_part='Head','Hat')));

Here's how I had to set the variable in the script.