Hello, the code I am posting sorts a pivot table but there can be only one statistic per row e.g Mean or Count.
I often have multiple statistics per row e.g Mean, Mode etc... .
I often have to generate multiple, long, pivot tables and to sort them manually is tedious made all
I the more so by having code that almost dose this for me.
All the pivot tables I make have the Mean as a row statistic, can some one see how to alter the following so I could sort on the Mean if there are multiple row statistics.
I am new to python, if this was VBA I could make a go at it.
I know it is not the best form to post a question were you ask: Please do this for me, but that is my skill level in python at the moment.
Thank for any assistance.
def sortTable(obj, i, j, numrows, numcols, section, more, custom):
"""Sort the rows of the table according to the selected column values
Cell formats are NOT updated, so the formats for all cells in a column
should be the same.
custom parameters is direction ('a', the default, or 'd')"""
if not section == "datacells":
return
direction = custom.get("direction", "a")
if not direction in ['a', 'd']:
print "direction must be 'a' or 'd'"
raise ValueError
PvtMgr = more.thetable.PivotManager()
numrowdims = PvtMgr.GetNumRowDimensions()
if numrowdims != 1:
print "Cannot sort table unless there is exactly one row dimension"
raise ValueError
col = j # sorting column