Create a list from one column in a power table

I’m trying to extract the values from only one column in a power table, create a dataset from it and write it to a tag. Basically, I want to trim the table dataset to the first column only. thanks

Where is the table getting its data from?
If it is a SQL query, you would be better off just creating the tag with a query of that column.
If it isn’t from a query then we can work up some code for you.

it is a manually made dataset, no bindings

tbl = event.source.parent.getComponent('Power Table')
tempDS = system.dataset.toPyDataSet(tbl.data)
hdr = ['Field']
newDS = []
for row in tempDS:
	newDS.append([row[0]])
system.tag.write('PathToDatasetTag',system.dataset.toDataSet(hdr,newDS))
1 Like

Use this function.

https://docs.inductiveautomation.com/display/DOC79/system.dataset.filterColumns

2 Likes

That works, thanks. Let me ask another question though. Right now I am manually creating the original power table’s dataset. on the property change event on the table I update the dataset tag, which you helped me with. Now, I want to take the dataset tag and use it to populate another table, in another window, using the tag as the headers for the table. the table should have only one row with all blanks. Would I be better off trying to do all this with a db table and queries?

Okay I’m getting close. When I run this code it sets the headers from the rows of the filtered data, but it displays as [u’element1’] instead of just element 1. What am I missing?

table = event.source.data
col = ['Element Name']
filter = system.dataset.filterColumns(table,col)
pyData = system.dataset.toPyDataSet(filter)
headers = []
dataOut = []
for row in pyData:
	headers.append([row[0]])	

system.tag.write("[Client]RegularElements", system.dataset.toDataSet(headers, dataOut))
if event.propertyName == "data":
	data = event.newValue
	columns = ['t_stamp',"ElementName"]
	filteredDataset = system.dataset.filterColumns(data,columns)
	
	system.tag.write("[Client]RegularElements", filteredDataset)
2 Likes