# How to sum the rows of a table with an expression in Vision

**URL:** <https://forum.inductiveautomation.com/t/how-to-sum-the-rows-of-a-table-with-an-expression-in-vision/75547>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [June 26, 2023, 7:30pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-the-rows-of-a-table-with-an-expression-in-vision/75547 "2023-06-26T19:30:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [June 26, 2023, 7:30pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-the-rows-of-a-table-with-an-expression-in-vision/75547/1 "2023-06-26T19:30:40Z")

</div>

Is there an easy way to do this? The number of columns is dynamic.

---

<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:** [June 26, 2023, 7:42pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-the-rows-of-a-table-with-an-expression-in-vision/75547/2 "2023-06-26T19:42:38Z")

</div>

Not for a varying number of columns, out of the box. The built in [sum()](https://docs.inductiveautomation.com/display/DOC81/sum) expression function will do a column at a time.

If you can programmatically determine which columns to include, you could use the `forEach()` function from my free Simulation Aids module to sum the sums. Something like this (for v8.1.8+):

```auto
sum(
	forEach(
		columnsOf({path.to.dataset}),
		if(
			{some.expression.yielding.true.to.include.column},
			sum({path.to.dataset}, idx()),
			null
		)
	)
)

```

The expression that determines whether to include a column can examine the column name as `it()[0]`, the column type as `it()[1]` (in string abbreviated form), or the column index as `idx()`.

---

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [June 26, 2023, 9:54pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-the-rows-of-a-table-with-an-expression-in-vision/75547/3 "2023-06-26T21:54:44Z")

</div>

sum() seems to work only with columns. I want to sum the rows.

---

<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:** [June 26, 2023, 9:57pm UTC](https://forum.inductiveautomation.com/t/how-to-sum-the-rows-of-a-table-with-an-expression-in-vision/75547/4 "2023-06-26T21:57:37Z")

</div>

Example input and output dataset, please. I'm pretty sure I can get `forEach()` to get you an answer.
