# Multiply dataset columns with number

**URL:** <https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258>\
**Category:** Ignition\
**Created:** [May 29, 2023, 12:00pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258 "2023-05-29T12:00:37Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [May 29, 2023, 12:00pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/1 "2023-05-29T12:00:37Z")

</div>

Hi ,

I have dataset . i want to **multiply 2,3,4 column with a number 0003**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/a/ca4490b716c348b3ecd1b40dabbe52c6bca29fea.png)

which method is good approach do this

please anyone help me out

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 29, 2023, 12:08pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/2 "2023-05-29T12:08:09Z")

</div>

If this dataset is coming from a SQL query, do it in the query itself:

```auto
SELECT t_stamp, Running, Starting * 3, Stop * 3, Stopping * 3 FROM...

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [May 29, 2023, 12:09pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/3 "2023-05-29T12:09:04Z")

</div>

noo i am getting from **system.tag.queryTagHistory**

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 29, 2023, 12:10pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/4 "2023-05-29T12:10:44Z")

</div>

With a script? What triggers it? How often does it populate the table?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [May 29, 2023, 12:16pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/5 "2023-05-29T12:16:43Z")

</div>

its in timer script. timer run for every one minute

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 29, 2023, 12:37pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/6 "2023-05-29T12:37:05Z")

</div>

That doesn't seem too bad for scripting. Try something like this:

```auto
table = event.source.parent.getComponent('Power Table')
#KWdataset = system.tag.queryTagHistory([...])
if isMMBTU:
	KWtoMMBTU_Multiplier = 3
	headers = system.dataset.getColumnHeaders(KWdataset)
	data = [[KWdataset.getValueAt(row, column) if column < 2 else KWdataset.getValueAt(row, column) * KWtoMMBTU_Multiplier 
				for column in range(KWdataset.columnCount)]
			for row in range(KWdataset.rowCount)]
	MMBTUDataset = system.dataset.toDataSet(headers, data)
	table.data = MMBTUDataset
else:
	table.data = KWdataset

```

**Edit:** Updated code to reflect the purpose of multiplying columns 2, 3, and 4 by 3

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [May 29, 2023, 1:11pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/7 "2023-05-29T13:11:04Z")

</div>

Thanks will try and let you know

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 30, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/8 "2023-05-30T15:42:50Z")

</div>

Also doable with `system.dataset.map` from my [Ignition Extensions](https://forum.inductiveautomation.com/t/ignition-extensions-convenience-utilities-for-advanced-users/64615) module.

Or you could get fancy and use a custom tag history aggregate:  
[https://docs.inductiveautomation.com/display/DOC81/Custom+Tag+History+Aggregates](https://docs.inductiveautomation.com/display/DOC81/Custom+Tag+History+Aggregates)

It would probably be _best_ to fix this data at the source, though. If these tag values should be 3x higher...why not enable tag scaling on the root tag, so you don't have to manually adjust history down the road?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [May 31, 2023, 4:19am UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/9 "2023-05-31T04:19:43Z")

</div>

Purpose of my approach

```
when user changes the unit from KW to MMBTU - i am doing this multiplication

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 31, 2023, 4:40am UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/10 "2023-05-31T04:40:27Z")

</div>

> [@prasath.t](#):
>
> Purpose of my approach

I was wondering what that [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)) was for. I've updated [my code example](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/6) to reflect this information.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [May 31, 2023, 4:53am UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/11 "2023-05-31T04:53:32Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/5/b577cc94e018c6415021029e9f372306b73b890a.png)  
for this conversion

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 31, 2023, 4:57am UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/12 "2023-05-31T04:57:23Z")

</div>

Uggh. 0.003412. When I first read the title, there wasn't a decimal. Columns number 2 & 4 look like an integer datatype, so imagine that a float conversion will be needed.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 31, 2023, 5:06am UTC](https://forum.inductiveautomation.com/t/multiply-dataset-columns-with-number/74258/13 "2023-05-31T05:06:38Z")

</div>

**Here is the corrected code:**

```auto
#define the following variables
'''
table = event.source.parent.getComponent('Power Table')#path to table
isMMBTU = condition that makes this true
KWdataset = system.tag.queryTagHistory([...])#complete query
'''
def setKWtoMMBTU(KWdataset):
	conversionFactor = 0.003412
	headers = system.dataset.getColumnHeaders(KWdataset)
	data = [[KWdataset.getValueAt(row, column) if column < 2 else float(KWdataset.getValueAt(row, column)) * conversionFactor 
				for column in range(KWdataset.columnCount)]
			for row in range(KWdataset.rowCount)]
	MMBTUDataset = system.dataset.toDataSet(headers, data)
	return MMBTUDataset
if isMMBTU:
	table.data = setKWtoMMBTU(KWdataset)
else:
	table.data = KWdataset

```
