# Report table calculation with a specific row

**URL:** <https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301>\
**Category:** Ignition\
**Created:** [March 20, 2023, 10:22am UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301 "2023-03-20T10:22:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Cockrell](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Brian\_Cockrell](https://forum.inductiveautomation.com/u/Brian_Cockrell)\
**Post date:** [March 20, 2023, 10:22am UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/1 "2023-03-20T10:22:12Z")

</div>

I am in need of some guidance.

I need to perform a calculation on a table that has 7 rows in the details rows based on the query.

I have a summary row and i need to calculate the difference between the last row in the details rows and the average row. I cant seem to find a way to specify the row number for use in the calculation.

Maybe i am just missing it but i cant seem to find it in the manual.

If anyone could help i would appreciate it.

---

<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:** [March 20, 2023, 10:49am UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/2 "2023-03-20T10:49:52Z")

</div>

> [@Brian\_Cockrell](#):
>
> cant seem to find it in the manual.

What context is this in? (Also, Perspective or Vision or Reporting?) An expression binding? In expressions, you can use these syntax options for dataset access:

- `{path/to/dataset}[0,0]`
- `{path/to/dataset}[0,'colName']`

In the square brackets, you put the zero-based row offset, and either the zero-based column offset or the column name.

---

<div class="post-metadata">

**Author:** ![Brian\_Cockrell](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Brian\_Cockrell](https://forum.inductiveautomation.com/u/Brian_Cockrell)\
**Post date:** [March 20, 2023, 11:17am UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/3 "2023-03-20T11:17:13Z")

</div>

This is in reporting using the table.

I need to subtract the average/summary from the last row in the list.

Header Row  
Data Row (Will always be 7 rows)  
Summary Row

Need to subtract summary row data from last or 7th row data row.

Thank You

---

<div class="post-metadata">

**Author:** ![Brian\_Cockrell](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Brian\_Cockrell](https://forum.inductiveautomation.com/u/Brian_Cockrell)\
**Post date:** [March 20, 2023, 11:19am UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/4 "2023-03-20T11:19:16Z")

</div>

I could always make a separate tag that could do this and place it in the summary but figured i should be able to do it without creating a seperate tag.

---

<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:** [March 20, 2023, 11:35am UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/5 "2023-03-20T11:35:51Z")

</div>

Hmm. No idea. I'd use a script data source to generate this.

---

<div class="post-metadata">

**Author:** ![Brian\_Cockrell](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Brian\_Cockrell](https://forum.inductiveautomation.com/u/Brian_Cockrell)\
**Post date:** [March 20, 2023, 11:47am UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/6 "2023-03-20T11:47:39Z")

</div>

Okay. Thanks

---

<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:** [March 20, 2023, 2:33pm UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/7 "2023-03-20T14:33:47Z")

</div>

You _can_ access rows in a table manually; I believe with a subscript style access similar to our dataset access, or maybe `@datakey.get(index)@`, so, in theory, you could do this aggregation manually.

But I agree with Phil, I'd probably just do this in scripting. Much easier to see (and change) the logic down the road.

---

<div class="post-metadata">

**Author:** ![Brian\_Cockrell](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Brian\_Cockrell](https://forum.inductiveautomation.com/u/Brian_Cockrell)\
**Post date:** [March 20, 2023, 5:18pm UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/8 "2023-03-20T17:18:47Z")

</div>

Thanks. I will test this.

---

<div class="post-metadata">

**Author:** ![Brian\_Cockrell](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Brian\_Cockrell](https://forum.inductiveautomation.com/u/Brian_Cockrell)\
**Post date:** [March 20, 2023, 5:49pm UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/9 "2023-03-20T17:49:31Z")

</div>

That doesnt seem to work. Just shows N/A

How would you oerform this in script?

---

<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:** [March 20, 2023, 6:33pm UTC](https://forum.inductiveautomation.com/t/report-table-calculation-with-a-specific-row/71301/10 "2023-03-20T18:33:21Z")

</div>

In an expression inside the summary row of a table:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/5/a514de831cab262ec1f84daa7690cc0de5e9f176.png)  
`Average without last: @(total.Column2 - static_data[count - 1].Column2) / (count - 1)@`

Where `static_data` is the name of the table's dataset, and `Column2` is the column you care about aggregating. The key is that from _anywhere_, you can retrieve any value from a dataset, you just need to 'fully qualify' your reference, e.g. `@static_data[1].Column2@` to get the value of column 2 at row 1. More on that syntax here: [http://www.reportmill.com/support/keychains.pdf](http://www.reportmill.com/support/keychains.pdf)

To do it in _scripting_, you could just generate a new data key that's based on your dataset. Doing the same as the other example could be something like this:

```python
def updateData(data, sample):
	pds = system.dataset.toPyDataSet(data["static_data"])
	runningSum = 0
	for row in pds[:-1]:
		runningSum += row["Column2"]
	data['summaryKey'] = runningSum / (len(pds) - 1)

```

Or, golfed a little bit:

```python
def updateData(data, sample):
	pds = system.dataset.toPyDataSet(data["static_data"])
	runningSum = sum(row["Column2"] for row in pds[:-1])
	data['summaryKey'] = runningSum / (len(pds) - 1)

```

The basic idea is the same, though - go through all the rows in the dataset _except_ the last one, and calculate the average off that.
