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

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?

Hey @victoria, thank you for your reply, I tried so many times and it was so simple! :expressionless:
I did change the name but I had to add more parenthesis

{{_.sum(table2.data.map(d=>_.parseInt(d.Total)))}}

1 Like

Ah yup! Pesky parentheses. Good catch :slightly_smiling_face:

HI i have a table where i need to sum only the select row and for selected columns only how can i do that

only the edited columns data need to sum and only selected row in table

Thanks this i have resolved

1 Like

Just a brief update that in our new table component, summing up table columns in a "summary row" should now be much easier to configure! Check out this comment :slightly_smiling_face: