# How to add custom row to SQL dataset?

**URL:** <https://forum.inductiveautomation.com/t/how-to-add-custom-row-to-sql-dataset/88484>\
**Category:** Maker\
**Tags:** perspective\
**Created:** [April 7, 2024, 6:34pm UTC](https://forum.inductiveautomation.com/t/how-to-add-custom-row-to-sql-dataset/88484 "2024-04-07T18:34:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [April 7, 2024, 6:34pm UTC](https://forum.inductiveautomation.com/t/how-to-add-custom-row-to-sql-dataset/88484/1 "2024-04-07T18:34:00Z")

</div>

Hi there,

I have an SQL query that gived me a dataset as shown below. I want to add new column to this dataset, where the value in each row should be calulated based on values in the other coumns. How can I do this?

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

I want to subtract the value in red from the value in blue, and place the result in green. And repeat this for all rows.

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

---

<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:** [April 7, 2024, 7:31pm UTC](https://forum.inductiveautomation.com/t/how-to-add-custom-row-to-sql-dataset/88484/2 "2024-04-07T19:31:37Z")

</div>

The simplest solution would be to use your DB's LAG() function to do that math right in the SQL.

```auto
SELECT *, kwh - LAG(kwh) OVER (ORDER BY Timesamp) AS delta_kwh
FROM ....

```
