I need to pivot a table and to do so, create a dataset with system.dataset.toDataSet(header, row).
The problem is that all the columns are in string type instead of int or double, and then the report cannot make any calculation on it.
I cannot initialize statically the header and the first row as the length is variable ; also, when I try to initialize the first row in the same loop as for the header, I get “IndexError: Row 0 doesn’t have the same number of columns as header list”…
#header
header.append(“Unité”)
for i in range (nbRow):
header.append(app.char.sans_accents(system.db.dateFormat(pODS[i][“t_stamp”],“MMM”)).upper())
#creation du new dataset
NDS = system.dataset.toDataSet(header, row)
#rows
for j in range(1,nbCol-1):
row.append(DS.getColumnName(j))
for i in range (nbRow):
row.append(int(pODS[i][j])*2)
NDS = system.dataset.addRow(NDS, row)
row = []
There is some magic that happens behind the scenes when the first data row is added to a dataset that determines what datatype each column should be. By creating a row with data in it first, it has a chance to guess correctly.
I’ve run into a smiler problem in the past where the different data rows rows held different data. In was fine in testing. The first row in production had a number in that column instead of a string so it complained on the second row.