# A way to do a SUMIF in an expression?

**URL:** <https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [June 17, 2020, 2:40pm UTC](https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756 "2020-06-17T14:40:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 17, 2020, 2:40pm UTC](https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756/1 "2020-06-17T14:40:35Z")

</div>

I have a main table with dollar value columns, and underneath it a totals table who’s data is just the `SUM()` expression of each column.

My main table also has a check box column, and I would like it so that if a few items are checked off, I only SUM those items instead of the whole row. Is there a way in expression bindings to do this, basically the equivalent of a `SUMIF` in excel?

---

<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:** [June 17, 2020, 3:53pm UTC](https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756/2 "2020-06-17T15:53:59Z")

</div>

Doing this in expressions is probably the wrong way to do it, in my opinion. I would make a pretty generic Python function and just use runScript; or, if you can avoid it entirely, property change/etc scripts directly.

Expressions aren’t well suited to handle datasets, since they lack any intermediate state operations (variable assignment) or looping operators.

---

<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:** [June 17, 2020, 3:54pm UTC](https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756/3 "2020-06-17T15:54:48Z")

</div>

That said, a `sumif()` expression function could go into an [ideas](https://ideas.inductiveautomation.com/) post 🙂

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 17, 2020, 4:23pm UTC](https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756/4 "2020-06-17T16:23:32Z")

</div>

Ok. I was afraid of that since it’s already all built with expressions, but a runScript would help me keep it in the same structure. Thanks.

I don’t suppose there’s a way to filter by a column to a dataset first in the expressions, or a cross-product ie column1 x column2 = result - that would also work given the 0 and 1 booleans on my check columns. I don’t see any off the bat but I know a lot of people here are very creative.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 17, 2020, 6:49pm UTC](https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756/5 "2020-06-17T18:49:55Z")

</div>

Not in expressions, but certainly doable in scripting.

+1 on doing this with a propertyChange script.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 17, 2020, 6:52pm UTC](https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756/6 "2020-06-17T18:52:01Z")

</div>

Of course, very little is not able to be done with scripting. I just enjoy when things can be done cleanly (or just cleverly) with expressions though. Guess its off to scripting I go.

---

<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 18, 2020, 12:26am UTC](https://forum.inductiveautomation.com/t/a-way-to-do-a-sumif-in-an-expression/35756/7 "2020-06-18T00:26:12Z")

</div>

This is trivial in my view() expression function:

```auto
view("SELECT max(valuecolumn) WHERE booleancolumn GROUP BY 1",
    {Root Container.path.to.dataset})

```
