Jump to content

To Calculate Avg after GrandTotals in Cross Tab - Spotfire


techg

Recommended Posts

Hi Techg,

Grand totals are displayed as the last row/column of your cross table. 

If you want to calculate an average after these totals you could try using an ironPython script. 

That is an example you could try and modify

from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataPropertyClass

# Get the active cross table
crossTable = Document.ActivePageReference.Visuals[0]

# Get the data table associated with the cross table
dataTable = crossTable.As[DataPropertyClass]().Data

# Create a new row for the average calculation
newRow = dataTable.NewRow()

# Iterate through the columns of the cross table
for column in crossTable.Columns:
    # If the column is not a grand total column
    if not column.IsGrandTotal:
        # Calculate the average for the column
        average = dataTable.Columns[column].RowValues.Average()
        # Add the average value to the new row
        newRow[column] = average

# Add the new row to the table
dataTable.AddRow(newRow)

# Refresh the cross table
crossTable.As[DataPropertyClass]().Data = dataTable


Let us know,

Best regards

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