Changing row with columns in table

I want to swap the rows for the columns. I have the following table binded to a named query

I would like one 2 columns, on the left the name of the product and on the right hand column the number

Product 1 32
Product 2 52
Product 3 9

Is this possible in the table properties? I have not been able to find a parameter to do this

It can be accomplished with a script transformation on the binding. The following should get you close if the Return Format it json.

	ret_value = [];
	for i in range(len(value)):
		for item in value[i]:
			new_row = {'name': item, 'value': value[i][item]}

	return ret_value
1 Like

If the data comes from a query, you can use the pivot operation,
otherwise you can do this with a script transform.

data = system.dataset.toPyDataSet(value)
return list(zip(*data))

This will pivot the whole thing, but get rid of the header and label each column ‘column 1’, ‘column 2’, etc.
If you want to keep the header and make it the first column, you can grab the header first, then add it to the list of things to zip:

header = system.dataset.getColumnHeaders(value)
data = system.dataset.toPyDataSet(value)
return list(zip(header, *data))

If you want to use a specific column as header, you’ll need some more manipulation. I’ll let you try it first.
Hint: system.dataset.filterColumns() might help you

1 Like

This worked great, thanks