# Rollup and average function on an array not available

**URL:** <https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996>\
**Category:** Ask for Help\
**Created:** [March 10, 2023, 2:45pm UTC](https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996 "2023-03-10T14:45:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morgan\_Taurines](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/morgan_taurines/32/55493_2.png) [@Morgan\_Taurines](https://community.glideapps.com/u/Morgan_Taurines)\
**Post date:** [March 10, 2023, 2:45pm UTC](https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996/1 "2023-03-10T14:45:31Z")

</div>

Hi,  
we have tried to use array function using numbers in different columns (

- Making an array is OK

- Sorting this array is also OK

- Slicing this sorted array is also OK

- but problmen when i want to make a roll up for the average of the above “final” array -\* just count and count unique functions are proposed

does someone get an idea of my problem?

thanks

Morga

---

<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:** [March 10, 2023, 3:48pm UTC](https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996/2 "2023-03-10T15:48:53Z")

</div>

Hola,

Try with this short JS code

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/6/667623a618816521e83a985c89a54ddde3000726.png)

```auto
let arr=p1.split(",").map(Number);
let N=p1.split(",").length;
let sum = 0;

arr.forEach(e => {
  sum+= e;
})

return (sum/N).toFixed(3)

```

Saludos @Morgan_Taurines !

---

<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:** [March 10, 2023, 11:58pm UTC](https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996/3 "2023-03-10T23:58:43Z")

</div>

The problem with this is Glide, by default, seems to not recognize array elements as numbers, but as text, hence only “count” and “count unique” are available.

---

<div class="post-metadata">

**Author:** ![Gui\_Rodrigues\_Goncal](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gui_rodrigues_goncal/32/41584_2.png) [@Gui\_Rodrigues\_Goncal](https://community.glideapps.com/u/Gui_Rodrigues_Goncal)\
**Post date:** [August 22, 2023, 1:33am UTC](https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996/4 "2023-08-22T01:33:45Z")

</div>

Hello @gvalero , maybe you can help me.

I used your Javascript as you posted above, but in my case not for Average. Just for Sum.

In this case it worked well when the numbers are integers, but I am receiving a “NaN” when the field has decimal numbers.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/6/462f69b92042664af3ae285abbde7cdac6fd27d8.jpeg)

Thank you

---

<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:** [August 22, 2023, 2:24am UTC](https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996/5 "2023-08-22T02:24:04Z")

</div>

I think it might have something to do with the comma.

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

Same method returns NaN.

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

Improvised method works.

```auto
let arr = p1.split('|').map(val => val.replace(',', '.')).map(Number);

let sum = 0;
arr.forEach(e => {
sum+= e;
})

return (sum).toFixed(3)

```

---

<div class="post-metadata">

**Author:** ![Gui\_Rodrigues\_Goncal](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gui_rodrigues_goncal/32/41584_2.png) [@Gui\_Rodrigues\_Goncal](https://community.glideapps.com/u/Gui_Rodrigues_Goncal)\
**Post date:** [August 22, 2023, 11:47am UTC](https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996/6 "2023-08-22T11:47:46Z")

</div>

Bingo!  
The question was related to the “comma” and the replace worked fine.

This community is really fantastic. When we are stuck with an issue we always have help.

Thank you very much @ThinhDinh

---

<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:** [August 22, 2023, 1:18pm UTC](https://community.glideapps.com/t/rollup-and-average-function-on-an-array-not-available/58996/7 "2023-08-22T13:18:14Z")

</div>

Thanks @ThinhDinh , nice fix!

Just a final warning to @Gui_Rodrigues_Goncal, try to avoid using the thousand (group) separator from number columns otherwise, other problems will come as you can see in my image:

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

Saludos!
