Jump to content
We've recently updated our Privacy Statement, available here. ×

Using Display Name of a Property (in IronPython or other)


Vincent Thuilot
Go to solution Solved by Vincent Thuilot,

Recommended Posts

Hello!

Sometimes when configuring properties we can have long expressions.

The issue I have today is that for the moment it seems one can only interact with the results of the property (Expressions), not the selection itself (Display Name). Probably i'm missing something!

Is there a way to use the Display Name of a property in calculations or in IronPython/Python/R scripts?

I could then use it easily in CASE WHEN statements or IF calculations. Long expressions using already other property values within aren't working in complex calculations, while the Display Name (Option1/Option 2 in the example attached) would make it I think.

Any idea? Thanks in advance for the support!

Using Display Name.JPG

Link to comment
Share on other sites

Hi Vincent,

I don't think this is possible at the moment. The only way I could see the Display names, was when creating a drop-down list. But what Spotfire stores in the document property, is the actual expression.
I'm not sure, if we can see the Display Name in a drop down list property control, where this information is stored. I will ask some of my colleagues if they know more about it.

Kind regards,

David

Link to comment
Share on other sites

On 4/26/2024 at 5:50 AM, Vincent Thuilot said:

Hello!

Sometimes when configuring properties we can have long expressions.

The issue I have today is that for the moment it seems one can only interact with the results of the property (Expressions), not the selection itself (Display Name). Probably i'm missing something!

Is there a way to use the Display Name of a property in calculations or in IronPython/Python/R scripts?

I could then use it easily in CASE WHEN statements or IF calculations. Long expressions using already other property values within aren't working in complex calculations, while the Display Name (Option1/Option 2 in the example attached) would make it I think.

Any idea? Thanks in advance for the support!

Using Display Name.JPG

You could use two Document Properties and IronPython to achieve this:

Step 1 - setup your property control. 

In this case, you would have your expression be the same as your display name or something short and easy to reference

image.png.be8e648db47b76f4755c5e2cd9a48bdd.png

Step 2 - create an additional property to store your custom expression (this will be referenced in step 3 IronPython code)

image.png.fb7ab26fcaf9f7981ddf78faea41584e.png

Step 3 - create an iron python script that is triggered when the first property control is changed. 

#Set your custom expressions here as variables
exp1 = "Sum(IF([Column1]='Yes',...))"
exp2 = "Sum(IF([Column2]='Yes'...))"
#...can set more options/expressions if desired

#If option 1 is selected, choose expression1. else use expression 2. etc
if Document.Properties["Options"] == "Option1":
 Document.Properties["OptionExpression"] = exp1
elif  Document.Properties["Options"] == "Option2":
 Document.Properties["OptionExpression"] = exp2
#...can set more options/expressions if desired

Then you can use Options property as a reference in other expressions/filters/calculated columns, and the OptionExpression property in value axes/expressions:
image.png.6e2514ba8a5754c4a10c98397cd54e74.png

  • Like 1
Link to comment
Share on other sites

  • Solution
Posted (edited)

Hello thanks Scott for the comment and proposal!

The main challenge was to find something flexible so I could use the same property to 1) calculate and display information on a map and 2) filter the data in another visual. That was this second point that was trickier than expected.

In the end I managed to find a solution that was less heavy, by doing as follow.

1- Switched from "Set property value through" initial setup which was "Expression" to Fixed Value

2- Kept the Display Name and copy paste the formulas i was using in Expression. The main difference here is that now the formulas are 100% recognized as text, Spotfire will not look after the parameters used within. I still needed the formulas for another visuals that is computing based on what is selected in the initial drop-down.

3- Since I wanted to keep it simple with IF or CASE WHEN statement, I added a condition using the first letters retrieved from the formula. First 20 characters starting from the LEFT and there we go.

These 3 steps made it possible to do it fast and without scripting: one visual is using the formulas whilst another visual is filtering based on what is selected in the same property !

Thanks a lot for sharing the idea with IronPython :)

 

 

 

Capture.JPG

Edited by Vincent Thuilot
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...