Sum an Array

Need to sum items in Car Services Array.
Tried rollup column, the sum option is not available.
tried js solutions available on the forum doesnt seem to work
Perhaps i am missing something

var n = p1, remainder, sumOfDigits = 0;
    remainder = n % 10;
    sumOfDigits = sumOfDigits + remainder;
    n = Math.floor(n/10);
return (sumOfDigits)


Your Car Services (column) is not an Array, it’s a List.

To convert it to Array column use a Split Text column and then you can use a Rollup column with no problem.


A few comments:

  • I agree with Gustavo. The “Car Services” column is a text column which contains comma-separated values. It’s not an array. As far as Glide is concerned a,b,c is one single string of text “a,b,c”.
  • The column type is text, so even after applying a Split Text column to turn the string “a,b,c” into an array [a,b,c], the underlying elements of the arrays will be seen as text, and therefore the Roll Up column will probably only offer count and count unique (there is nothing to sum with text).
  • If you want to be able to sum numbers, I think it would be better to gather numeric responses from your users in numeric columns.
  • By any chance are you on a Pro plan? If so, this might be a good use case for the Glide AI Text to Number feature: feed text as the input, get number values as the output. Even though, the input here would be a text CSV, so I’m not exactly sure how that would work. I’m curious though.

The Car Services is dropdown, which is attached to

with the services displaying in dropdown but the values are linked to the price.
Manual input of prices is really the last option.
Any other way to work around it?

I see. In the choice component, you could write the names of the services (or better, the Row IDs) instead of the prices. Turn the csv into an array, relate to your pricing table, and sum through the relation. Or pull in the prices with a lookup.

Bottom line: write the services instead of the prices, then fetch the prices with a relation.

1 Like

This :point_up:

1 Like