Rollup and average function on an array not available

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

Hola,

Try with this short JS code

image

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 !

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.

1 Like

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.

Thank you

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

Same method returns NaN.

Improvised method works.

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

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

return (sum).toFixed(3)
2 Likes

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

1 Like

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

Saludos!

2 Likes