# Summing up in a DataGrid column

**URL:** <https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192>\
**Category:** How do I?\
**Created:** [June 23, 2023, 10:07am UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192 "2023-06-23T10:07:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![icos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/icos/32/4625_2.png) [@icos](https://community.weweb.io/u/icos)\
**Post date:** [June 23, 2023, 10:07am UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/1 "2023-06-23T10:07:30Z")

</div>

There is a DataGrid element and a database is connected to it. The database has a column with the type “decimal”. There is no way to sum up such a column in the DataGrid (as I understand it). I decided to put the calculation under the DG. How to write the formula correctly? I tried it this way

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/5/5088c772763bd75b079c15974a24a875686ab659.png), but it doesn’t work.

---

<div class="post-metadata">

**Author:** ![jaredgibb](https://avatars.discourse-cdn.com/v4/letter/j/ecd19e/32.png) [@jaredgibb](https://community.weweb.io/u/jaredgibb)\
**Post date:** [June 23, 2023, 10:36am UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/2 "2023-06-23T10:36:05Z")

</div>

Is this a dynamic value I.e can be updated by the user on the fly or always the sum of all those values in the collection array?

---

<div class="post-metadata">

**Author:** ![icos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/icos/32/4625_2.png) [@icos](https://community.weweb.io/u/icos)\
**Post date:** [June 23, 2023, 11:32am UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/3 "2023-06-23T11:32:13Z")

</div>

The amount should change when a new line is added.

---

<div class="post-metadata">

**Author:** ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)\
**Post date:** [June 23, 2023, 1:59pm UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/4 "2023-06-23T13:59:15Z")

</div>

Your path is incorrect, it seems that there is a “payload” structure

Is it working on your datagrid?

I will advise updating your collection so that the data are what’s inside payload, and not an object with a key payload and data inside

---

<div class="post-metadata">

**Author:** ![icos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/icos/32/4625_2.png) [@icos](https://community.weweb.io/u/icos)\
**Post date:** [June 23, 2023, 2:18pm UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/5 "2023-06-23T14:18:33Z")

</div>

Like this?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/9/95eb57e1388dd7cd373c298f1349cbf58fa4abc7.png)  
I’m experimenting. Since Directual’s Front is weak, I do it in Weweb. Connected via Rest API.

---

<div class="post-metadata">

**Author:** ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)\
**Post date:** [June 23, 2023, 2:42pm UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/6 "2023-06-23T14:42:52Z")

</div>

No, on the collections settings itself.  
The first argument of sum need tl be an array or a collection.  
But a collection is normally returning an array. When you define your collection, (i suppose here its a rest api collection) you can define a key to get the data (payload here).  
You should see your collection display correctly on the right after that (on the collection panel)

---

<div class="post-metadata">

**Author:** ![icos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/icos/32/4625_2.png) [@icos](https://community.weweb.io/u/icos)\
**Post date:** [June 23, 2023, 3:17pm UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/7 "2023-06-23T15:17:16Z")

</div>

On the first screenshot, the first argument is Collection. I don’t quite understand how to determine the key, Directual doesn’t have such a function. you mean this one?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/1/1b71ab25a5a81ac95dc179baca3e83ea3ef898a5.png)  
Or did I misunderstand?

---

<div class="post-metadata">

**Author:** ![icos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/icos/32/4625_2.png) [@icos](https://community.weweb.io/u/icos)\
**Post date:** [June 27, 2023, 8:35am UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/8 "2023-06-27T08:35:02Z")

</div>

Can you help me?

---

<div class="post-metadata">

**Author:** ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)\
**Post date:** [June 27, 2023, 1:03pm UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/9 "2023-06-27T13:03:33Z")

</div>

On your last screenshot, you can see a result\_key field. This should be set to payload on the collection you displayed on your first message.

---

<div class="post-metadata">

**Author:** ![icos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/icos/32/4625_2.png) [@icos](https://community.weweb.io/u/icos)\
**Post date:** [June 28, 2023, 4:15pm UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/10 "2023-06-28T16:15:14Z")

</div>

I’m not quite sure how this helps me, I have a text field underneath the DataGrid. I need it to display the sum of one of the columns in the table. Or did I get it wrong?

---

<div class="post-metadata">

**Author:** ![icos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/icos/32/4625_2.png) [@icos](https://community.weweb.io/u/icos)\
**Post date:** [July 4, 2023, 9:19pm UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/11 "2023-07-04T21:19:23Z")

</div>

Hi.  
And yet, back to my question. How to summarize the data?

---

<div class="post-metadata">

**Author:** ![Joyce](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joyce/32/13232_2.png) [@Joyce](https://community.weweb.io/u/Joyce)\
**Post date:** [July 4, 2023, 10:37pm UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/12 "2023-07-04T22:37:36Z")

</div>

Hi @icos 👋

Can you try this:

`sum(rollup(Budget Exp.data.payload[0],"summ_expens"))` (Note: I don’t think this will work if you copy/paste it from here but it should work if you write the formula in WeWeb)

This is what’s happening

- `rollup(Budget Exp.data.payload[0],"summ_expens")` will return all the values of “summ\_expens”
- then if you wrap a `sum` around it, all those values should be summed

Does that do the trick for you?

---

<div class="post-metadata">

**Author:** ![icos](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/icos/32/4625_2.png) [@icos](https://community.weweb.io/u/icos)\
**Post date:** [July 5, 2023, 10:51am UTC](https://community.weweb.io/t/summing-up-in-a-datagrid-column/3192/13 "2023-07-05T10:51:26Z")

</div>

Finally, it worked).  
Thank you so much, Joyce.
