# Writing one column from a dataset tag to a new dataset tag

**URL:** <https://forum.inductiveautomation.com/t/writing-one-column-from-a-dataset-tag-to-a-new-dataset-tag/26638>\
**Category:** Ignition\
**Created:** [July 17, 2019, 6:56pm UTC](https://forum.inductiveautomation.com/t/writing-one-column-from-a-dataset-tag-to-a-new-dataset-tag/26638 "2019-07-17T18:56:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jomo23](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jomo23](https://forum.inductiveautomation.com/u/jomo23)\
**Post date:** [July 17, 2019, 6:56pm UTC](https://forum.inductiveautomation.com/t/writing-one-column-from-a-dataset-tag-to-a-new-dataset-tag/26638/1 "2019-07-17T18:56:03Z")

</div>

I’m trying to write one column from a dataset tag to a new dataset tag so I can link the tag to my template I will be creating. The dataset tag I am pulling from currently has 6 columns however I only want information from 1 column. I tried using the system.tag.read(“first dataset tag”).value.getValueAt(1,"Title of the Column) and was able to get the first row of information but I would like to obtain all the rows for this column. I don’t know how to specify that I want all the rows on the dataset tag rather than a specific row. I then plan on writing the information to my new dataset tag and was wondering what the best method would be.

Thanks,  
Jo

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 17, 2019, 7:56pm UTC](https://forum.inductiveautomation.com/t/writing-one-column-from-a-dataset-tag-to-a-new-dataset-tag/26638/2 "2019-07-17T19:56:54Z")

</div>

I wrote this one a while back for a rainy day. This one looks convoluted, but it will work with both BasicDataSets and PyDataSets, and can return either type as its output.

```python
def colToDataSet(dataset, colName, returnPyDataSet = False):
	# Check to see if input really is a dataset, then create data appropriately.
	if str(type(dataset)) == "<type 'com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities$PyDataSet'>":
		data = [[row[colName]] for row in dataset]
	elif str(type(dataset)) == "<type 'com.inductiveautomation.ignition.common.BasicDataset'>":
		colData = dataset.getColumnAsList(dataset.getColumnIndex(colName))
		data = [[item] for item in colData] 
	else:
		raise Exception("Input is not a dataset")

	if returnPyDataSet:
		return system.dataset.toPyDataSet(system.dataset.toDataSet([colName], data))
	else:
		return system.dataset.toDataSet([colName], data)

	
tagIn = '[default]path/to/source/tag'
tagOut = '[default]path/to/destination/tag'
columnName = 'Column Name'

dataIn = system.tag.read(tagIn).value

system.tag.write(tagOut, colToDataSet(dataIn, columnName))

```

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [July 17, 2019, 8:02pm UTC](https://forum.inductiveautomation.com/t/writing-one-column-from-a-dataset-tag-to-a-new-dataset-tag/26638/3 "2019-07-17T20:02:10Z")

</div>

To expand a bit on Jordan’s answer, as you found out, `getValueAt` only returns a single cell. You need a function that will return an entire column.

If you want a simpler one that works with a tag, you can try this:

```auto
# read the full dataset from the tag
data = system.tag.read("[default]MyDatasetTag").value

# extract only the column we want
smallData = system.dataset.filterColumns(data, ["Col 2"])

# display it somewhere so we know it worked
event.source.parent.getComponent('Table 1').data = smallData

```

---

<div class="post-metadata">

**Author:** ![jomo23](https://avatars.discourse-cdn.com/v4/letter/j/f6c823/32.png) [@jomo23](https://forum.inductiveautomation.com/u/jomo23)\
**Post date:** [July 17, 2019, 8:13pm UTC](https://forum.inductiveautomation.com/t/writing-one-column-from-a-dataset-tag-to-a-new-dataset-tag/26638/4 "2019-07-17T20:13:42Z")

</div>

Thank you Kathy! It worked like a charm and was simple to understand.

---

<div class="post-metadata">

**Author:** ![Rusty](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rusty/32/19859_2.png) [@Rusty](https://forum.inductiveautomation.com/u/Rusty)\
**Post date:** [December 2, 2020, 7:36pm UTC](https://forum.inductiveautomation.com/t/writing-one-column-from-a-dataset-tag-to-a-new-dataset-tag/26638/5 "2020-12-02T19:36:09Z")

</div>

> [@KathyApplebaum](#):
>
> # extract only the column we want smallData = system.dataset.filterColumns(data, ["Col 2"]) # display it somewhere so we know it worked event.source.parent.getComponent('Table 1').data = smallData

Hello Kathy,

This seems like what I'm looking for, but is there a way to use this in an expression dataset tag expression?

For example: Tag1 is a dataset with 5 columns. I would like Tag2 to be a dataset containing column1 of Tag1. Can this be done as an expression instead of as an action script?

Thank you
