How do I count or sum the content of multiple table rows?

So I have a table:

Item Name (Col1), Amount (Col2) x 5 rows

How Can I get the total sum of 'amount' from the 5 rows?

thx,
Toby

Hi @toby! Are you looking to do something like this?

In my example, you could also just do {{ currentRow.film_id + currentRow.inventory_id + currentRow.store_id }} instead of using the _.sum function.

1 Like

More the other way round, sum store_id

but what you did has given me an idea, so I'll have a look and update back.

T

So there's no current column selection which is a bit blah.

So will need to figure out another way.. ideas?

If I understood correctly, you can just create a JS query that SUMS up the Total cell of all columns, wouldn't that work for you?

yup - Just not clear on how to access that data?

Ah! While I don't believe there is a currentColumn or anything similar, would something like this work for you?

1 Like

ohh I knew it would something dumb - So yes this is the trick. Thought in my case it's counting non-intergers (booleans and strings), so need to work on that.

Hello,
I have the same problem. I verified the name of the column and it is the same but I got 0 as result ("not defined")
How can I do please?
Thanks

Hello! :slightly_smiling_face: Happy to help.

Would you mind sharing a screenshot of what you're currently looking at / what's currently returning 0?

Hi, I belive I have the same issue. I did test the simple example you provided nov 21, at that works fine. But, using my real data, I am not able to sum price-column. Any advice?

Hi @lars_lysenstoen!

Thank you for the screenshot. You’ll notice in the little preview that table1.data is an array containing objects containing column names and values.

table1.data.price doesn’t actually return anything

However, since we want an array of all the price values, we can first convert our data object from an array of objects to an object of arrays (where each array contains all the values for each column):

formatDataAsObject(table1.data)

Then we can grab the price array like:

formatDataAsObject(table1.data).price

And now to sum it all up,

_.sum(formatDataAsObject(table1.data).price)

Let me know if you have any questions about this at all!

1 Like

Thanks a lot, it solved my issue :slight_smile:

So happy to hear that! Write back in anytime :slightly_smiling_face:

Hello, I am having the same problem, but now seem to be getting strings. I am just trying to get a total from a column from my table. Many Thanks, Thomas

Hi @webm4ster !

You could definitely solve this - what if you tried something like:

{{_.sum(table1.data.map(d=>_.parseInt(d.total_price)}}

This will format your data in a way that allows for it to be summed :slight_smile:

Thank you for your response and proposed solution. Sadly that didn't seem to work for me :frowning: I'll keep trying.

Hey @webm4ster darn!

Can you send your data formatting? I'm sure we can figure out a solution for you here.

Hi Joey, I have the same problem, but unfortunately this didn't work for me :frowning:
I really don't know how to do this... would you be so kind to help me?

Thank you so much!

Hey @Alex9000! Have you tried changing total_price to the name of your own table column?