# Changing row with columns in table

**URL:** <https://forum.inductiveautomation.com/t/changing-row-with-columns-in-table/54036>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [December 13, 2021, 9:45am UTC](https://forum.inductiveautomation.com/t/changing-row-with-columns-in-table/54036 "2021-12-13T09:45:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Resistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/resistor/32/30634_2.png) [@Resistor](https://forum.inductiveautomation.com/u/Resistor)\
**Post date:** [December 13, 2021, 9:45am UTC](https://forum.inductiveautomation.com/t/changing-row-with-columns-in-table/54036/1 "2021-12-13T09:45:20Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/b/ebe815e2c4db2f65eb28a668b4dffdd2f292e2ea.png)

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

---

<div class="post-metadata">

**Author:** ![mcgheeiv](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mcgheeiv](https://forum.inductiveautomation.com/u/mcgheeiv)\
**Post date:** [December 13, 2021, 10:39am UTC](https://forum.inductiveautomation.com/t/changing-row-with-columns-in-table/54036/2 "2021-12-13T10:39:23Z")

</div>

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

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

	return ret_value

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 13, 2021, 10:47am UTC](https://forum.inductiveautomation.com/t/changing-row-with-columns-in-table/54036/4 "2021-12-13T10:47:43Z")

</div>

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

```python
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:

```python
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

---

<div class="post-metadata">

**Author:** ![Resistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/resistor/32/30634_2.png) [@Resistor](https://forum.inductiveautomation.com/u/Resistor)\
**Post date:** [December 14, 2021, 10:39am UTC](https://forum.inductiveautomation.com/t/changing-row-with-columns-in-table/54036/5 "2021-12-14T10:39:10Z")

</div>

This worked great, thanks
