# Combining datasets

**URL:** <https://forum.inductiveautomation.com/t/combining-datasets/2719>\
**Category:** Ignition\
**Created:** [March 3, 2011, 8:34pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/2719 "2011-03-03T20:34:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimE](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@TimE](https://forum.inductiveautomation.com/u/TimE)\
**Post date:** [March 3, 2011, 8:34pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/2719/1 "2011-03-03T20:34:12Z")

</div>

Hi,

I have 9 datasets in the root container of a window and each dataset has two columns; ‘item’ and ‘value’. I want to combine these to one dataset. How do I do this?

Note: each dataset is bound to a rather complicated query that I would prefer not to mess with.  
Translation: I am too lazy to change it and I am looking for an easier way.

Thank you,

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [March 3, 2011, 10:07pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/2719/2 "2011-03-03T22:07:42Z")

</div>

It is a little tricky since you cannot combine datasets in binding, you have to do it in scripting. You can put a propertyChange script on the Root Container that if any of the datasets change you can create a new combined one. Add the following code to a propertyChange script of the Root Container:[code]if event.propertyName == “ds1” or event.propertyName == “ds2”:  
ds1 = event.source.ds1  
ds2 = event.source.ds2  
header = [“Item”, “Value”]  
data = []

```
def addData(ds):
	import system
	data = []
	for row in system.dataset.toPyDataSet(ds):
		data.append([row[0], row[1]])
	return data

data.extend(addData(ds1))
data.extend(addData(ds2))

event.source.combined = system.dataset.toDataSet(header, data)[/code]You can add more than just two datasets ds1 and ds2. This code goes through and creates a whole new dataset out of the previous ones and sets it to the combined dataset on the Root Container in my case.
```

---

<div class="post-metadata">

**Author:** ![TimE](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@TimE](https://forum.inductiveautomation.com/u/TimE)\
**Post date:** [March 4, 2011, 5:22pm UTC](https://forum.inductiveautomation.com/t/combining-datasets/2719/3 "2011-03-04T17:22:58Z")

</div>

Thank you, it works great! ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://forum.inductiveautomation.com/u/Robert)\
**Post date:** [March 5, 2011, 4:03am UTC](https://forum.inductiveautomation.com/t/combining-datasets/2719/4 "2011-03-05T04:03:48Z")

</div>

You can also use a union. You don’t have to mess with the queries, just cut/past them all into one with a UNION between each.
