Tip of the Week

Displaying Cross Table data as a new Data Table

When using a Cross Table to display various measurements and calculations on your data, it is sometimes useful to be able to use the aggregated data elsewhere in your document.  This could be so you can use it in other visualizations, or so you can build custom reports with the data.  Using a Script Control, you can programmatically access this data and add it back into Spotfire as a new Data Table, which will then allow it to be used in other visualization types and other reports.

Assume we have the following Cross Table:

The following script will take in one parameter, which is a reference to the Cross Table above:

from System.IO import Path, File, StreamWriter
from Spotfire.Dxp.Data import DataTableSaveSettings
from Spotfire.Dxp.Application.Visuals import CrossTablePlot
from Spotfire.Dxp.Data.Import import TextFileDataSource
from Spotfire.Dxp.Data.Import import TextDataReaderSettings
from Spotfire.Dxp.Application.Visuals import TablePlot
from Spotfire.Dxp.Application.Visuals import VisualTypeIdentifiers

#Temp file for storing the cross table data
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()

#Export CrossTable data to the temp file
writer = StreamWriter(tempFilename)
crossTable.As[CrossTablePlot]().ExportText(writer)

#Add tempfile back into Spotfire using TextFileDataSource
readerSet = TextDataReaderSettings()
readerSet.Separator = "\t"
readerSet.AddColumnNameRow(0)
textDataSource = TextFileDataSource(tempFilename, readerSet )
myNewTable = Document.Data.Tables.Add("CrossTableData",textDataSource)

#If you want to change the data table to be embedded and not linked, use the following code
settings = DataTableSaveSettings (myNewTable,False, False);
Document.Data.SaveSettings.DataTableSettings.Add(settings);


When the script is executed a new Data table is added, which is displayed on the top of the image below: 

In next week's tip we will learn how to take this new Data table, or any Data table, and build a custom report, using colors and styles, and images, which will print out much nicer than the raw Data table would.

Comments

 

David Mosenkis said:

This is a nice approach especially for complex cross tables.  But it's worth noting that for many cross tables, including the one in this example, another way to get the data into a separate data table is using File->Add Data Tables->Add->From Analysis, and apply a pivot transformation.  In addition to not requiring coding, this approach has the advantage that if the initial data table is linked, then the 2nd data table will be automatically updated with the new data whenever the file is opened.

March 8, 2011 11:11 AM
 

Tip of the Week said:

Last week we discussed how to take an aggregated table visualization, like a cross table, and export

March 13, 2011 10:20 PM
 

bitom said:

avid, this is right, but I have a pivot problem which can only be solved via a cross-table.

I have results of many research compounds over many methods in a lean table with 3 different columns for operator, value & unit. If you pivot it , all operator columns are shown first, then all value columns, then all unit columns. You can then rearrange the table, but if you save it as an analysis and next time you have new methods loaded, the sorting is gone....it can only be solved with a cross table...

...that is a very helpful tip to me...

Kind regards

Thomas

March 23, 2011 9:25 AM
 

Tip of the Week said:

This is the final tip in a three part series, where we learn how to build custom HTML reports in TIBCO

April 4, 2011 10:52 AM
 

bitom said:

Dear Spotfire colleagues,

we have tried the "Tip of the week - Displaying Cross Table data as a new Data Table" and it worked, but we have an open issue. Sometimes, we use more than one clunmn header, up to 5, to generate a cross table in a certain sorting order. If we now convert this cross table via the script to a regular table, it recognizes only the first column header as a header and regards all other headers already as data rows.

Is there a way to solve this within the script?

Thanks and kind regards

BITOM

April 8, 2011 1:42 AM
 

Kunal said:

There is a column avg(sales), avg(unit)  this column contains value as Number so when we import this cross table in spotfire it automatically takes string formatting for this column, is it possible to import with number formatting.

Can any one help me on this.

Thanks in advance

Kunal Prajapati

April 21, 2011 1:34 AM
 

Christopher Ammacher said:

I receive the following error message.  Please assist.

Microsoft.Scripting.Runtime.UnboundNameException: name 'crossTable' is not defined

  at IronPython.Runtime.PythonContext.MissingName(SymbolId name)

  at Microsoft.Scripting.Runtime.LanguageContext.LookupName(CodeContext context, SymbolId name)

  at Microsoft.Scripting.Runtime.RuntimeHelpers.LookupName(CodeContext context, SymbolId name)

  at <module>$57##57(Closure , Scope , LanguageContext )

  at Microsoft.Scripting.Runtime.OptimizedScriptCode.InvokeTarget(LambdaExpression code, Scope scope)

  at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)

  at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)

  at Spotfire.Dxp.Application.ScriptSupport.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)

  at Spotfire.Dxp.Application.Scripting.ScriptService.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)

  at Spotfire.Dxp.Application.Scripting.ScriptManager.<>c__DisplayClassd.<ExecuteScriptForDebugging>b__c()

  at Spotfire.Dxp.Framework.Commands.CommandHistory.Transaction(String displayName, Executor executor, Boolean visible, Boolean sticky, Guid stickyGuid)

  at Spotfire.Dxp.Framework.Commands.CommandHistory.Transaction(String displayName, Executor executor)

  at Spotfire.Dxp.Framework.DocumentModel.DocumentNode.Transaction(String displayName, Executor executor)

  at Spotfire.Dxp.Framework.DocumentModel.DocumentNode.Spotfire.Dxp.Framework.DocumentModel.ITransactions.ExecuteTransaction(Executor executor)

  at Spotfire.Dxp.Application.Scripting.ScriptManager.ExecuteScriptForDebugging(String scriptCode, Dictionary`2 scriptArguments, String& output)

  at Spotfire.Dxp.Forms.Framework.Scripting.ScriptEditDialog.RunButton_Click(Object sender, EventArgs e)

May 4, 2011 3:23 PM
 

ithcel said:

The idea looks good. But I dont want to use pivot option just to avoid inconsistencies error on web player.

Even by changing crosstab into a data table while running the analysis on professional it is asking to set the Import setting box.

how can we avoid that and make the analysis open without any prompts?

June 20, 2011 1:25 PM
 

msanchez37 said:

How do you specify the parameter?

Thank you!

Michael Sanchez

August 26, 2011 1:38 PM
 

msanchez37 said:

I have a problem that is similar to this: Is there as way to create a new data table out of a Details-On-Demand table or Details-Visualization?

The overall problem I am trying to solve is to populate a property with a list of elements that I have selected from a map visualization, and call an Oracle stored procedure with that list of elements as a parameter. Since a property can be populated from unique values in a column, I figured that since the details on demand table shows the selected elements, I could set up the property control to populate from the unique values in details on demand table. But the property control dialog does not allow this, so I figure that if I created the details on demand table as a regular Spotfire table, I get get to the same end.

So, Is there a way to create create a new data table out of a Details-On-Demand table or Details-Visualization? Is there a better way to get the desired list of data elements to Oracle?

Thank you in advance!

Michael Sanchez

November 21, 2011 7:41 PM
 

RichardLeiden said:

I have the same problem as Christopher Ammacher (see above)

I'm using Spotfire Pro v3.1, is that the problem ?

December 13, 2011 5:27 AM
 

anitha said:

can we export data from Datatable to excel

December 27, 2011 7:28 AM
 

uggkensington said:

http://www.uggkensingtons.org/

http://www.uggkensingtons.org/ugg-fox-fur-short-boots-5531-c-54.html | UGG Fox Fur Short Boots 5531

http://www.uggkensingtons.org/ugg-kensington-boots-5678-c-2.html | UGG Kensington Boots 5678

http://www.uggkensingtons.org/ugg-rainier-eskimo-boots-5189-c-85.html | UGG Rainier Eskimo Boots 5189

http://www.uggkensingtons.org/ugg-retro-cargo-boots-1895-c-3.html | UGG Retro Cargo Boots 1895

December 27, 2011 8:17 PM
 

uggskensingtonsale said:

www.uggskensingtonsale.org

www.uggskensingtonsale.orgugg-adirondack-boots-ii-c-6.html | UGG Adirondack Boots II

www.uggskensingtonsale.orgugg-adirondack-tall-boots-c-11.html | UGG Adirondack Tall Boots

www.uggskensingtonsale.orgugg-amberlee-boots-c-34.html | UGG Amberlee Boots

www.uggskensingtonsale.orgugg-annabelle-boots-c-35.html |

December 28, 2011 4:22 AM
 

uggretrocargosale said:

January 4, 2012 8:45 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit

Syndication

Other Spotfire Blogs

Spotfire's interactive information visualization and analytic solutions give users a remarkable experience for quickly and easily querying data and reporting results for superior business intelligence. From portfolio management and customer retention programs to key processes such as CRM, marketing, research, bioinformatics, yield and asset management and design for manufacturing, enterprises around the world rely on Spotfire's business analytics software to improve operational performance.

©Copyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center