# How can I sum numbers in an array?

**URL:** https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405
**Category:** Ask for Help
**Created:** [November 11, 2021, 6:06pm UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405 "2021-11-11T18:06:48Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Simon\_Hill](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simon_hill/32/94730_2.png) [@Simon\_Hill](https://community.glideapps.com/u/Simon_Hill)
#### Post date: [November 11, 2021, 6:06pm UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/1 "2021-11-11T18:06:48Z")

</div>

Any quick tip on how to sum numbers in an array?

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/5/f51257127358bf72c273e8594790840cfab6d7d1.png)

I would like to add a column that sums the numbers in the array of numbers in the last column. The array is a simple list of numbers, appended by the row.

---

<div class="post-metadata">

### Author: ![PabloMFalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pablomfalero/32/31166_2.png) [@PabloMFalero](https://community.glideapps.com/u/PabloMFalero)
#### Post date: [November 11, 2021, 7:27pm UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/2 "2021-11-11T19:27:22Z")

</div>

Use a rollup column

---

<div class="post-metadata">

### Author: ![Simon\_Hill](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simon_hill/32/94730_2.png) [@Simon\_Hill](https://community.glideapps.com/u/Simon_Hill)
#### Post date: [November 11, 2021, 7:34pm UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/3 "2021-11-11T19:34:48Z")

</div>

Nope. Doesn’t work… the sum option is not available.

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/7/570d07448ba3bf649503053866a7d9256495bbdc.png)

---

<div class="post-metadata">

### Author: ![BlakeWS](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/blakews/32/24377_2.png) [@BlakeWS](https://community.glideapps.com/u/BlakeWS)
#### Post date: [November 11, 2021, 8:03pm UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/4 "2021-11-11T20:03:34Z")

</div>

Related: I would like the count of instances of an item from an array.

![array](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/5/15238f894cae63de74989f10a745098c6145f99e.png)

---

<div class="post-metadata">

### Author: ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)
#### Post date: [November 11, 2021, 11:10pm UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/5 "2021-11-11T23:10:03Z")

</div>

Interesting! 🤔

I didn’t know that a Rollup column can count the items of array in each row, thanks for the tip!

However, your goal is the sum right?.. I think a customized JS code can do it easy:

This is my code by using an EC:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/0/30d7613460abe160469db541dba462c14381b296.png)

```auto
let len=p8.length;
let x=0, total =0;

while (x< len) {
   total+= parseInt(p8[x]);
   x++ ;
}
return total

```

The problem here is that [Glide’s JavaScript plugin](https://www.glideapps.com/plugins/hell-yes-code) does not support an array as input value so you must use another version or create a new version of that JavaScript plugin.

Maybe @david can read this note and carry out an improvement of his plugin to support these cases.

My version to work with this case runs on Replit:

> [https://SNB-YesCode.gustavovalero.repl.co](https://SNB-YesCode.gustavovalero.repl.co)

Hope it helps you!

Feliz noche @Simon_Hill

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [November 11, 2021, 11:27pm UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/6 "2021-11-11T23:27:28Z")

</div>

What are you using to get that rolling total array? Seems like it’s being read as text.

---

<div class="post-metadata">

### Author: ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)
#### Post date: [November 12, 2021, 12:58am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/7 "2021-11-12T00:58:04Z")

</div>

Right!

It is the reason why I use **parseInt()** in the code. This covers all cases so far.

**Edited**  
I already know what you mean Thind, of course, if the arrays have numeric values the Rollup operation would have worked perfectly!!

Saludos!

---

<div class="post-metadata">

### Author: ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)
#### Post date: [November 12, 2021, 1:04am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/8 "2021-11-12T01:04:24Z")

</div>

This seems like an oversight. @mark @david?

---

<div class="post-metadata">

### Author: ![david](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david/32/62831_2.png) [@david](https://community.glideapps.com/u/david)
#### Post date: [November 12, 2021, 2:08am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/9 "2021-11-12T02:08:07Z")

</div>

What is this `Rolling total array` column? How is it configured? Glide does not recognize it as an array of numbers.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/0/f0bdf8b0fa4fcb26fd5f86ed08033c99b4cc509a.jpeg)

---

<div class="post-metadata">

### Author: ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)
#### Post date: [November 12, 2021, 2:26am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/10 "2021-11-12T02:26:44Z")

</div>

> [@BlakeWS](#):
>
> ![array](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/5/15238f894cae63de74989f10a745098c6145f99e.png)

Hola @BlakeWS

You can try with this JS code until Glide’s JavaScript plugin can support arrays as input values (parameter)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/7/97bcbcfd8db5ca809e52b30595af6a059d3cf9b8.png)

```auto
let len=p8.length;
let total=0;

for (let x= 0; x< len; x++) {
   if (p1==p8[x])  
      total ++
}
return total

```

My Source’s URL on Replit is :

> [https://snb-yescode.gustavovalero.repl.co](https://snb-yescode.gustavovalero.repl.co)

Saludos!

---

<div class="post-metadata">

### Author: ![david](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david/32/62831_2.png) [@david](https://community.glideapps.com/u/david)
#### Post date: [November 12, 2021, 3:08am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/11 "2021-11-12T03:08:37Z")

</div>

@gvalero or:

```auto
return p8.filter(x => x === p1).length

```

😉

---

<div class="post-metadata">

### Author: ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)
#### Post date: [November 12, 2021, 3:16am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/12 "2021-11-12T03:16:47Z")

</div>

Right!

I had forgotten the Filter() method 🥴

Sometimes I like the old-programming school (C++) 😀

Gracias por el tip @david

---

<div class="post-metadata">

### Author: ![BlakeWS](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/blakews/32/24377_2.png) [@BlakeWS](https://community.glideapps.com/u/BlakeWS)
#### Post date: [November 12, 2021, 3:22am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/13 "2021-11-12T03:22:47Z")

</div>

Thanks @gvalero & @david , it works great.

---

<div class="post-metadata">

### Author: ![Simon\_Hill](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simon_hill/32/94730_2.png) [@Simon\_Hill](https://community.glideapps.com/u/Simon_Hill)
#### Post date: [November 12, 2021, 8:10am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/14 "2021-11-12T08:10:16Z")

</div>

Hi David, thanks for taking the time.

Here is a quick video to explain… I think you’re right, Glide does not recognize the array is comprised of numbers.

Any quick fix?

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 12, 2021, 8:45am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/15 "2021-11-12T08:45:32Z")

</div>

hmm, I’m surprised that isn’t working. Will be interested to see what the outcome is…

---

<div class="post-metadata">

### Author: ![Simon\_Hill](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/simon_hill/32/94730_2.png) [@Simon\_Hill](https://community.glideapps.com/u/Simon_Hill)
#### Post date: [November 12, 2021, 9:43am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/16 "2021-11-12T09:43:00Z")

</div>

Interesting to note that the roll-up with sum works on the full array of 12 numbers. It stops working after splicing the array.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/4/c4b01daad6cc18a338655da6e9c7f15b962bbf6a.png)

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 12, 2021, 10:15am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/17 "2021-11-12T10:15:24Z")

</div>

yeah, kinda suggests that the Array Splice isn’t actually returning an array.

---

<div class="post-metadata">

### Author: ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)
#### Post date: [November 12, 2021, 11:28am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/18 "2021-11-12T11:28:52Z")

</div>

Hola Darren,

I think the Slice Array plugin is doing its job but the result is always a Text therefore, the Rollup column can’t sum text values.

Bye

---

<div class="post-metadata">

### Author: ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)
#### Post date: [November 12, 2021, 11:49am UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/19 "2021-11-12T11:49:56Z")

</div>

yes, that’s what I meant. It’s not returning an array.

---

<div class="post-metadata">

### Author: ![david](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/david/32/62831_2.png) [@david](https://community.glideapps.com/u/david)
#### Post date: [November 12, 2021, 1:33pm UTC](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405/20 "2021-11-12T13:33:17Z")

</div>

Yes! I bet the array columns all deal with arrays of ‘primitives’, which allows them to work on arrays of anything, but this causes the resulting array to lose type information (the Slice Array column ‘forgets’ what kind of array it’s slicing).

In regular programming, the solution to this is called Generics or polymorphism. I have some research projects to discuss with @Ivo_Elbert about this soon.

[Next page](https://community.glideapps.com/t/how-can-i-sum-numbers-in-an-array/34405.md?page=2)
