Suming up rows in my Perspective Table

I am using a Perspective Table and I would like to sum up the values in one of the column and show them in a LED display. Is it possible if I can do that in Ignition?

I’m sure there’s probably a more pythonic way to manage this, but this is what I did:

the transform attached to this binding makes a list out of the populations of the default data, then uses a Python built-in sum() function to obtain their sum.

The only golfing I’d do with Cody’s suggestion is add that the square brackets for the list comprehension aren’t required; since sum is already a terminal operation and only requires visiting each element once, you don’t need to collect the results into a list at all (and thus you can save some memory):
sum(row.population for row in value)

1 Like

I couldnt see the screenshot , could you please reattach the screenshot again please!

I tried with my Perspective Table , but I get the following error:

Because your props.data is a dataset, instead of a list of values. You’ll need to iterate through the rows of your Dataset, or get just the column you’re trying to sum.

sum(value.getColumnAsList(x))  # where x is the index of the column you're trying to sum

sum(value.getColumnAsList(value.getColumnIndex("columnName")))
As long as the column is in fact numeric, that should work.

EDIT: Good catch Cody :slight_smile:

1 Like

I tried the sum(value.getColumnAsList(“columnName”)) but still getting the Error_ScriptEval. I have attached a screenshot along with this message. Thanks again for your help!

Thanks Cody, that worked

2 Likes