# How to perform calculations in a column of a table?

**URL:** <https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [April 8, 2024, 3:58pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528 "2024-04-08T15:58:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Armando\_Rivero\_Rubal](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Armando\_Rivero\_Rubal](https://forum.inductiveautomation.com/u/Armando_Rivero_Rubal)\
**Post date:** [April 8, 2024, 3:58pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/1 "2024-04-08T15:58:46Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/f/8f4383e372030d037ff0f5f7cc7a018dd099c14c.png),

How can I make the difference of the field (Maximum) - (Minimum) and put it in the Total field.  
It is to be able to calculate the Energy per hour from a historical data obtained from an electric energy meter

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 8, 2024, 4:01pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/2 "2024-04-08T16:01:01Z")

</div>

Welcome to the forum, Armando.  
Can you edit (pencil icon) and add an English translation - even [https://translate.google.com](https://translate.google.com) - to the title and the post?

---

<div class="post-metadata">

**Author:** ![Armando\_Rivero\_Rubal](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Armando\_Rivero\_Rubal](https://forum.inductiveautomation.com/u/Armando_Rivero_Rubal)\
**Post date:** [April 8, 2024, 4:03pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/3 "2024-04-08T16:03:49Z")

</div>

ok

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 8, 2024, 4:04pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/4 "2024-04-08T16:04:14Z")

</div>

I think you are asking how to calculate the difference between Maximo and Minimum. You should do this in your SQL query.

```auto
SELECT
    t_tstamp,
    Maximo,
    Minimo,
    (Maximo - Minimum) AS Total
FROM
    ....

```

---

<div class="post-metadata">

**Author:** ![Armando\_Rivero\_Rubal](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Armando\_Rivero\_Rubal](https://forum.inductiveautomation.com/u/Armando_Rivero_Rubal)\
**Post date:** [April 8, 2024, 5:16pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/5 "2024-04-08T17:16:09Z")

</div>

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

The data in the table is from this Tag History query, where should your code go?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 8, 2024, 5:54pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/6 "2024-04-08T17:54:32Z")

</div>

Add the tag with the Range aggregation mode.

---

<div class="post-metadata">

**Author:** ![Armando\_Rivero\_Rubal](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Armando\_Rivero\_Rubal](https://forum.inductiveautomation.com/u/Armando_Rivero_Rubal)\
**Post date:** [April 8, 2024, 6:19pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/7 "2024-04-08T18:19:14Z")

</div>

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

From the same TAg I have the Maximum and the minimum value every 5 minutes, and I need to subtract those values

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 8, 2024, 6:22pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/8 "2024-04-08T18:22:31Z")

</div>

Using Historian will not work well. You will miss some data.

![Maximo not the same](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/2/a25b6c16dee49153587eee2c60f204cd540cadec.png)

You need these numbers to be the same. Historian does not work the way you think it does.

You could ignore the minimum and use a script to calculate  
diff = Maximon - Maximon-1

---

<div class="post-metadata">

**Author:** ![Armando\_Rivero\_Rubal](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Armando\_Rivero\_Rubal](https://forum.inductiveautomation.com/u/Armando_Rivero_Rubal)\
**Post date:** [April 8, 2024, 6:54pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/9 "2024-04-08T18:54:39Z")

</div>

Sorry, but I'm new to this, and I don't know where I should enter the Script, I will have to get the data from the TAg History where the energy meter is being stored, RIGHT?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 8, 2024, 9:12pm UTC](https://forum.inductiveautomation.com/t/how-to-perform-calculations-in-a-column-of-a-table/88528/10 "2024-04-08T21:12:26Z")

</div>

Below your Tag History Binding there should be an Add Transform button. Hit that and select Script.

Someone else will have to help you with the script as I don't have a test database at the moment.
