Jump to content

How to format the cell values of a crosstable using ironpython.

Prateek Rawat 3

Recommended Posts

In my dashboard I have a crosstable which has some calculations happening based on user input through 2 input fields document properties. The input could be any number b/w 1 and 1000.

Few of the calculations(cell values) are formatted as percentage and few as numbers.

Issue is whenever someone enters a new value in the input field the formatting of the cell values goes away and it is not possible to format it for all the combinations b/w 1 and 1000.

Is there a way to fix this?

I have tried to do it with below ironpython script but it is not working for multiple columns:

from Spotfire.Dxp.Data import * 

from Spotfire.Dxp.Application.Visuals import *

from Spotfire.Dxp.Data.Formatters import *

myVis = myVis.As[Visualization]()

formatter = DataType.Real.CreateLocalizedFormatter()

formatter1 = DataType.Real.CreateLocalizedFormatter()

# Set the formatter category to Percentage

percent.Category = NumberFormatCategory.Percentage

number.Category = NumberFormatCategory.Number

# Set "Decimals:" option:

percent.DecimalDigits = 1  

percent.GroupSeparatorEnabled = True

number.DecimalDigits = 0  

number.GroupSeparatorEnabled = True

myVis.Formatting.IndexedRealFormatter['Sum(sales)'] = percent

myVis.Formatting.IndexedRealFormatter["Count(orders)"] = number

The above script formats the first column i.e Sum(sales) and does not format Count(orders).

Also, it doesn't work with aliases, for example:

myVis.Formatting.IndexedRealFormatter["Sum(sales) as [Total Sales]"] = percent #This does not work

Is there a workaround?

Link to comment
Share on other sites

  • 2 weeks later...

Formatting.thumb.png.6f2f89df59d039d485695281e5712345.pnghi Gaia,

In the attached image on the left hand side I have two input boxes A and B and on right hand side there is a cross table where there are few dynamic calculations based on the A and B.

I have set the format of no. of pages column to number with 0 decimals and % of pages to percentage with 0 decimals.

Issue is that when I change the values in A or B input boxes, the formatting of these columns goes away as shown in the screenshot which is there in the bottom.

Is there a solution to this?

I was trying to handle it using ironpython script but it doesn't seem to work.

Link to comment
Share on other sites

Hi Gaia,

In the crosstable I have put a dynamic alias name for below custom expression:

SUM(If(SN([no. of days open],${A}-1) > ${A} and SN([no. of days open], ${B}+1 ) <= ${B},[no.of open questions],0))/SUM([Total questions]) as [${A} and ${B} no. of days].

I observed that when I remove the dynamic alias name the formatting works fine on changing the input field values, but if I put the dynamic alias name back the formatting goes away whenever I change the values.

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...