Running Totals

Hi Glide Community,

Is there a way of calculating running totals in the Glide data editor?

I am trying to replicate the below that can be done in Google Sheets but seems to be very difficult in Glide as roll ups are column specific, unless using a relation/lookup/specific array setups.

Screen Shot 2022-05-03 at 7.02.23 PM
Screen Shot 2022-05-03 at 7.02.37 PM

Is there a way of doing a running total like this? I have tried a different ways with arrays and using the row index but still no luck. Any help would be appreciated!!

Justin

Here are the steps to do it exclusively within Glide.

  • Add a rowID column.

  • Add an IDs array: lookup all rowIDs within this table.

  • Add an index column, use the plugin Array > Find Element Index.

  • Add a template column to lock in the format of the number.

  • Add a joined list column to join all the “template” numbers.

  • Add a JavaScript column to calculate the running total using the list of numbers and the index of each row.

let numbers = p1.split("||");

let total = 0;

for (i = 0; i <= p2; i++) {
total += parseInt(numbers[i]);
}

return total;
5 Likes

Hola!

Here a shorter version of Thinh’s idea by using a helper column as index (which is sequential and you must keep and not change it)

image

The steps are:

  1. Create an index column to have a sequence of rows (IDX)
  2. Create a Joined List based on Qty column
    image
  3. Type this JS code using IDX column and new Joined List column as parameters
var arr=p1.split("|").map(Number);
var suma =0;
for (i=0; i< p2; i++)   {
    suma += arr[i];
}
return suma

I hope it helps you.

Saludos!

3 Likes

Thank you both!! You are amazing and certainly saved me from future damage to my head … considering all the banging on the wall I was doing trying to do this completely natively in Glide without JS. :joy:

I am more partial to Thinh’s solution here as having the index calculated via array allows the list to change without other intervention.

It would be amazing if this could be a regular calculation in Glide in future without having to resort to additional JS.

Also to note, thanks Thinh for going above and beyond and actually using the same sheet/numbers I was using! You guys both rock. Hope this thread will help others in future.

4 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.