Create Pivot Table with IronPython Script

I've been struggling to get a pivot script working.  My problem is accurately identifying the Category, Value, and Identity columns.

I think I have the Identity columns fine.  I want the Categories (column headers) to be the unique values from "CLASS DESCRIPTION" in SrcTable.  I want the values inside each of the Category columns to be Count( CLASS_DESCRIPTION ).  So if for a set of identity columns, there are 4 instances of CLASS DESCRIPTION = "403A", I want a column titled "403A" with value 4.

See my current script below.  I commented the section I'm having trouble with.

--------------------------------------------------------------------------------------------------------

from Spotfire.Dxp.Data import DataFlowBuilder, DataColumnSignature, DataType, DataSourcePromptMode
from Spotfire.Dxp.Data.Transformations import PivotTransformation
from Spotfire.Dxp.Data.Transformations import ColumnAggregation
from System.Collections.Generic import List
from Spotfire.Dxp.Data.Import import DataTableDataSource

SrcTable=Document.Data.Tables["Raw Data"]
ds=DataTableDataSource(SrcTable)
dfb=DataFlowBuilder(ds,Application.ImportContext)
pt=PivotTransformation()
IdentityCols=[]
IdentityCols.append(DataColumnSignature(SrcTable.Columns["LAYER"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["DMS DEVICE"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["SCAN DATE TIME"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["LOT"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["WAFER ID"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["SLOT ID"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["SCAN TOOL"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["TOTAL DEFECTS"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["TOTAL DEFECTS CLASSIFIED"]))
IdentityCols.append(DataColumnSignature(SrcTable.Columns["TOTAL DIE WITH DEFECTS"]))

 

# HERE'S WHERE MY PROBLEMS ARE STARTING
CategoryCols=[]
CategoryCols.append(DataColumnSignature(SrcTable.Columns["CLASS DESCRIPTION"]))

# IN THIS SECTION, I KEEP GETTING AN ERROR "expected IDataColumn, got ColumnAggregation"
# AT THE LIST2.ADD LINE
list2 = List[ColumnAggregation]()
list2.Clear()
col = SrcTable.Columns['CLASS DESCRIPTION']
colAg = ColumnAggregation(DataColumnSignature(col),'Count')
list2.Add(DataColumnSignature(colAg))
pt.ValueColumns = list2

pt.IdentityColumns=List[DataColumnSignature](IdentityCols)
pt.CategoryColumns=List[DataColumnSignature](CategoryCols)
dfb.AddTransformation(pt)
flow=dfb.Build()
Document.Data.Tables["Wafer Total"].ReplaceData(flow)

-----------------------------------------------------------------------------------------------------------

 

Thanks for the help!

(1) Answer

Login