Search code examples
spotfire

Adding multiple columns in a spotfire custom expression


I am trying to create a button to change a bar chart to switch between 2 columns on the y axis (side by side bars) and 1 column. First option of toggle: First option of toggle Second option of toggle: Second option of toggle I am using a button that increments a document property by 1 each time it is clicked, and a custom expression for the y axis which checks the value of the document property and changes the axis accordingly. The custom expression is an if statement, checking if it is odd or even, and then changing the columns. (Side note - I have not tried solving this using an iron python script)

I tried

If( ${DocProp} % 2 = 0, (UniqueCount([moa]) , UniqueCount([jp_cluster])),(UniqueCount([moa])))

But received the error:

Expected ')' but found ',' on line 1 character 37.

I knew the comma between the two columns might cause a problem by interfering with the if statement, so I tried a case statement:

case ${RemoveJPCluster} % 2 when 0 then (UniqueCount([moa]), UniqueCount([jp_cluster])) else UniqueCount([moa]) end

But this throws the same error:

Expected ')' but found ',' on line 1 character 44.

I have also tried: + AND NEST

Any help on this? Is it even possible? I don't know why I can't surround the two columns with brackets and call it a day...


Solution

  • I am not sure why that does not work, probably as you suspect the comma gets in the way.

    Instead of creating a DocProp with values 1 or 2, you could directly put the desired expressions in it. So you add a text area with a drop down list assigned to DocProp.

    Set property value through: Fixed values, then assign two entries as:

    Display Name: 1 (or whatever you want)

    Value: UniqueCount([moa])

    Display Name: 2

    Value: UniqueCount([moa]), UniqueCount([jp_cluster])

    Then populate your Value Axis with ${DocProp} directly.