Step 1: Adding Dimensions (Python)
You add dimensions to a pivot table with the Append or Insert method.
Example: Using the Append Method
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
coldim=table.Append(spss.Dimension.Place.column,"coldim")
rowdim1=table.Append(spss.Dimension.Place.row,"rowdim-1")
rowdim2=table.Append(spss.Dimension.Place.row,"rowdim-2")
- The first argument to the
Append
method specifies the type of dimension, using one member from a set of built-in object properties:spss.Dimension.Place.row
for a row dimension,spss.Dimension.Place.column
for a column dimension, andspss.Dimension.Place.layer
for a layer dimension. - The second argument to
Append
is a string that specifies the name used to label this dimension in the displayed table. - Although not required to append a dimension, it's good practice to store a reference to the newly created dimension object in a variable. For instance, the variable rowdim1 holds a reference to the object for the row dimension named rowdim-1. Depending on which approach you use for setting categories, you may need this object reference.

The order in which the dimensions are appended determines how they are displayed in the table. Each newly appended dimension of a particular type (row, column, or layer) becomes the current innermost dimension in the displayed table. In the example above, rowdim-2 is the innermost row dimension since it is the last one to be appended. Had rowdim-2 been appended first, followed by rowdim-1, rowdim-1 would be the innermost dimension.
Note: Generation of the resulting table requires more code than is shown here.
Example: Using the Insert Method
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
rowdim1=table.Append(spss.Dimension.Place.row,"rowdim-1")
rowdim2=table.Append(spss.Dimension.Place.row,"rowdim-2")
rowdim3=table.Insert(2,spss.Dimension.Place.row,"rowdim-3")
coldim=table.Append(spss.Dimension.Place.column,"coldim")
- The first argument to the
Insert
method specifies the position within the dimensions of that type (row, column, or layer). The first position has index 1 (unlike typical Python indexing that starts with 0) and defines the innermost dimension of that type in the displayed table. Successive integers specify the next innermost dimension and so on. In the current example, rowdim-3 is inserted at position 2 and rowdim-1 is moved from position 2 to position 3. - The second argument to
Insert
specifies the type of dimension, using one member from a set of built-in object properties:spss.Dimension.Place.row
for a row dimension,spss.Dimension.Place.column
for a column dimension, andspss.Dimension.Place.layer
for a layer dimension. - The third argument to
Insert
is a string that specifies the name used to label this dimension in the displayed table. - Although not required to insert a dimension, it is good practice to store a reference to the newly created dimension object to a variable. For instance, the variable rowdim3 holds a reference to the object for the row dimension named rowdim-3. Depending on which approach you use for setting categories, you may need this object reference.

Note: Generation of the resulting table requires more code than is shown here.