# Running Totals

**URL:** <https://community.glideapps.com/t/running-totals/41596>\
**Category:** Ask for Help\
**Created:** [May 3, 2022, 11:04pm UTC](https://community.glideapps.com/t/running-totals/41596 "2022-05-03T23:04:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinjmp](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/justinjmp/32/43205_2.png) [@justinjmp](https://community.glideapps.com/u/justinjmp)\
**Post date:** [May 3, 2022, 11:04pm UTC](https://community.glideapps.com/t/running-totals/41596/1 "2022-05-03T23:04:20Z")

</div>

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](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/f/af61d3ccc739563131a22e1820875172d7ad990e.png)  
 ![Screen Shot 2022-05-03 at 7.02.37 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/c/3cebff68cdb8c7a0b139faeb479ace5d7147ad24.png)

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

---

<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:** [May 3, 2022, 11:51pm UTC](https://community.glideapps.com/t/running-totals/41596/2 "2022-05-03T23:51:10Z")

</div>

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

Here are the steps to do it exclusively within Glide.

- Add a rowID column.

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

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

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

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

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

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

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

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

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

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

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

let total = 0;

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

return total;

```

---

<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:** [May 4, 2022, 3:53am UTC](https://community.glideapps.com/t/running-totals/41596/3 "2022-05-04T03:53:07Z")

</div>

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](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/d/5d4f5ce470b71c2af952be72f6af16c29fa71f55.png)

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](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/f/5fb224bcc37cb887d327912bcafcf2bc594fc92a.png)
3. Type this JS code using IDX column and new Joined List column as parameters  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/6/76f11bab53601942d1fd374a67061e3116afcbe6.png)

```auto
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!

---

<div class="post-metadata">

**Author:** ![justinjmp](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/justinjmp/32/43205_2.png) [@justinjmp](https://community.glideapps.com/u/justinjmp)\
**Post date:** [May 4, 2022, 4:52pm UTC](https://community.glideapps.com/t/running-totals/41596/4 "2022-05-04T16:52:36Z")

</div>

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. 😂

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.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [May 5, 2022, 4:52pm UTC](https://community.glideapps.com/t/running-totals/41596/5 "2022-05-05T16:52:37Z")

</div>

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