Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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)
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.
Hi Lucas,
May be
count({<[Clothing]={Text($(clothing))}>} distinct Color)
Regards,
Andrey
try
count({<[Clothing]={'$(clothing)'}>} distinct Color)
OR
count({<[Clothing]={'$(=clothing)'}>} distinct Color)
Try
count({<[Clothing]={"$(=clothing)"}>} distinct Color
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
Can you change let to set when defining your variable? You should store the string then evaluate in the set expression.
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?
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.