Search code examples
listboxexpressionuser-inputspotfire

Spotfire list box selections to create new column values


I'm absolutely flummoxed as to where I've gone wrong here.

I'm trying to test if the user selected input (from a List Box (Multiselect)) matches the value within a column and then assigning categories accordingly.

My expression:

case 
$map("when [Column] = ${ListBoxMulti} then 'User_selected_value'", " ")
else 'Default' 
END 

where ListBoxMulti is the name of my list box property.

The resulting expression is (with example selections from list box):

case 
when [Column] = 1 then 'User_selected_value' when [Column] = 24 then 'User_selected_value'
else 'Default' 
END

My best guess was that the error was popping up because the second "when" statement is not on a new line. However, when I tried this variation:

case 
$map("when [Column] = ${ListBoxMulti} then 'User_selected_value'", "\n")
else 'Default' 
END

the new line character was just interpreted as a string:

case 
when [Column] = 1 then 'Control'\nwhen [Column] = 24 then 'User_selected_value'
else 'Default' 
END

I also tried using addition "" as escapes to show that I wanted a new line character, but all of it was interpreted as a string.

Finally, I tried an if statement I found here (which appeared to do EXACTLY what I needed), that I tried to tweak to my needs:

if(find([Column],"$map("${ListBoxMulti}", "&")")>0, "Yes", "No" )

which results in the following expression:

if(find([Column],"1&24")>0, "Yes", "No" )

All of these just have a sample result of #ERROR and I have absolutely zero idea where I'm going wrong. Any help would be HUGELY appreciated.


Solution

  • It might depend on what the datatype of the entries in your listbox is compared to the datatype in your column. The new line does not matter. Try maybe putting quotes around the document properties in your original expression (works for me):

    case 
    $map("when [Column] = '${ListBoxMulti}' then 'User_selected_value'", " ")
    else 'Default' 
    END