# Customizing tables, adjustable date

**URL:** <https://forum.inductiveautomation.com/t/customizing-tables-adjustable-date/20423>\
**Category:** Ignition\
**Created:** [October 29, 2018, 4:17am UTC](https://forum.inductiveautomation.com/t/customizing-tables-adjustable-date/20423 "2018-10-29T04:17:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan.wiebe](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dan.wiebe](https://forum.inductiveautomation.com/u/dan.wiebe)\
**Post date:** [October 29, 2018, 4:17am UTC](https://forum.inductiveautomation.com/t/customizing-tables-adjustable-date/20423/1 "2018-10-29T04:17:45Z")

</div>

I wanted to sharre this here for 2 reasons.  
1., incase someone else is looking for something similar (as i was)  
2. incase there is room for improvement/optimization

i built this script as a table so i can poll the history of some tags from tag historian database based on the dates in a trend slider. this script is in the table of the data and drops it into a new table that is on the forefront.  
I did this because grabbing the dataset directly from the trend was giving me min/max values not closest value like i wanted.  
It allows converting data between metric/imperial values as well and then i can export it.  
This is for Pressure and temperature. As you can see, the values in the database for history are saved as Metric.  
Metric property is 0 for metric, 1 for imperial, comes from a dropdown list.

Also the Date and the time are separated in the formatting.

```auto
if event.propertyName == "data" or event.propertyName == "metric":
	# bring dataset from this table into script
	dats = event.source.data
	# metric or imperial? if metric do this
	if event.source.metric == 0:	
		newhdr = ["yyyy-mm-dd", "hh:mm:ss", "Pressure (kPa)", "Temp. (degC)"]
		pconv = 1.0
		tcon1 = 1.0
		tcon2 = 0.0
	# metric or imperial? if imperial do this
	if event.source.metric == 1:	
		newhdr = ["yyyy-mm-dd", "hh:mm:ss", "Pressure (psi)", "Temp. (degF)"]
		pconv = 0.145033
		tcon1 = 1.8
		tcon2 = 32.0
	newdat = []
	# get the data from the old dataset, modify it, and then place it into the new dataset row by row
	for row in range(dats.rowCount):
		a = system.date.format(dats.getValueAt(row, 0), "yyyy-MM-dd")
		b = system.date.format(dats.getValueAt(row, 0), "hh:mm:ss")
		c = dats.getValueAt(row, 1)
		cc = (c * pconv)
		d = dats.getValueAt(row, 2)
		dd = ((d * tcon1) + tcon2)
		newdat.append([a, b, cc, dd])
	# build the new dataset with headers and data
	dataset = system.dataset.toDataSet(newhdr, newdat)
	# this sends the new modified dataset to the new table on top of the master table (this is the master table)
	event.source.parent.getComponent('Table2').data = dataset
```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 29, 2018, 4:44am UTC](https://forum.inductiveautomation.com/t/customizing-tables-adjustable-date/20423/2 "2018-10-29T04:44:04Z")

</div>

You don’t have to use two tables. Just add a custom dataset property to one, where you bring in the raw data, then process it and write it to the table’s data property.

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 29, 2018, 10:24am UTC](https://forum.inductiveautomation.com/t/customizing-tables-adjustable-date/20423/3 "2018-10-29T10:24:37Z")

</div>

Also if you have a property called ‘metric’, I think it is better to make this mean metric when it is true i.e. 1, not metric when it is 0.

---

<div class="post-metadata">

**Author:** ![dan.wiebe](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dan.wiebe](https://forum.inductiveautomation.com/u/dan.wiebe)\
**Post date:** [November 6, 2018, 2:36am UTC](https://forum.inductiveautomation.com/t/customizing-tables-adjustable-date/20423/4 "2018-11-06T02:36:37Z")

</div>

yes i did change that, i should have called this imperial, as the data comes in as metric in the first place.

---

<div class="post-metadata">

**Author:** ![dan.wiebe](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dan.wiebe](https://forum.inductiveautomation.com/u/dan.wiebe)\
**Post date:** [November 6, 2018, 2:37am UTC](https://forum.inductiveautomation.com/t/customizing-tables-adjustable-date/20423/5 "2018-11-06T02:37:07Z")

</div>

good point thank you
