# How to auto-calculate one of the 2 fields - amount and balance - to update based on the value in another

**URL:** <https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365>\
**Category:** Ask for Help\
**Created:** [March 19, 2023, 2:24pm UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365 "2023-03-19T14:24:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![siraj-samsudeen](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/siraj-samsudeen/32/54801_2.png) [@siraj-samsudeen](https://community.glideapps.com/u/siraj-samsudeen)\
**Post date:** [March 19, 2023, 2:24pm UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/1 "2023-03-19T14:24:42Z")

</div>

I am new to glide and I am trying to create an expense tracker for my personal use, just to get off the ground with a real project.

I have the following columns:  
date, amount,balance, category.

When I enter the amount, I want the balance to be updated by taking the previous balance (from the previous row). Sometimes, I just want to enter the balance and want an entry made for the amount.

Should I create balance as an explicit column in my table (and a typical excel formula to take the previous row value and subtract the amount to get the value for current row) , or should I use a calculated field (something like a running calculation in DB terms) - any guidance or pointers would be appreciated.

---

<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 20, 2023, 12:08am UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/2 "2023-03-20T00:08:18Z")

</div>

So do you have a Users table and an Expenses table, and want to show a live balance to the user?

---

<div class="post-metadata">

**Author:** ![siraj-samsudeen](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/siraj-samsudeen/32/54801_2.png) [@siraj-samsudeen](https://community.glideapps.com/u/siraj-samsudeen)\
**Post date:** [March 29, 2023, 10:42am UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/3 "2023-03-29T10:42:29Z")

</div>

I am sorry for the delay in responding - yes, i have these 2 tables and want to show a live balance to the user, ideally as he enters each transaction

---

<div class="post-metadata">

**Author:** ![Xavier\_Delplanque](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/xavier_delplanque/32/45565_2.png) [@Xavier\_Delplanque](https://community.glideapps.com/u/Xavier_Delplanque)\
**Post date:** [March 29, 2023, 2:29pm UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/4 "2023-03-29T14:29:35Z")

</div>

> [@siraj-samsudeen](#):
>
> When I enter the amount, I want the balance to be updated by taking the previous balance (from the previous row). Sometimes, I just want to enter the balance and want an entry made for the amount.

Maybe a spreadsheet of the end result you’d like could help?

---

<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 30, 2023, 1:04am UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/5 "2023-03-30T01:04:42Z")

</div>

Assuming you store the amounts in the same column (positive and negative, accordingly), it would just be a rollup on top of a relation to sum that column, but as Xavier said, we might have a better recommendation if you show us your data structure.

---

<div class="post-metadata">

**Author:** ![siraj-samsudeen](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/siraj-samsudeen/32/54801_2.png) [@siraj-samsudeen](https://community.glideapps.com/u/siraj-samsudeen)\
**Post date:** [March 30, 2023, 11:53am UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/6 "2023-03-30T11:53:54Z")

</div>

Here is a screenshot from the google sheets I am using. When the user enters the amount, the balance should be displayed to him - here when he enters 200, he should see the closing balance as 19,300 by taking the opening balance of 19500 (from the previous entry) and deducting the 200.

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

---

<div class="post-metadata">

**Author:** ![Xavier\_Delplanque](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/xavier_delplanque/32/45565_2.png) [@Xavier\_Delplanque](https://community.glideapps.com/u/Xavier_Delplanque)\
**Post date:** [March 30, 2023, 7:26pm UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/7 "2023-03-30T19:26:37Z")

</div>

Got it!  
It’s probably a lot easier to do in google sheet this way than in Glide tables 😉  
I gave it a try, but I end up with a circular dependency

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

Not having to define the related balance for each individual record is a lot easier though.  
The user may need to see the balance only when he adds a new expense.

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [March 30, 2023, 8:03pm UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/8 "2023-03-30T20:03:40Z")

</div>

Some ideas discussed here.

> [@How to create a cumulative sum of rows in a columns](https://community.glideapps.com/t/how-to-create-a-cumulative-sum-of-rows-in-a-columns/46181):
>
> Hi, Is there a way in Glide to create a cumulative sum of the rows in a column, like adding up monthly sales ? Jan Jan+Feb Jan+Feb+Mars Jan+Feb+Mars+Apr etc… Thanks!

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [March 30, 2023, 9:02pm UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/9 "2023-03-30T21:02:25Z")

</div>

I’d probably write the previous balance when creating each row, then use a math column to figure out the new balance based on the credit or debit.

You could get that previous balance before creating a new row by using a Single Value column or a Rollup column. Either way you should have a balance value that you can pass through a form when you write a new row, and then the math column will give you the new balance.

---

<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:** [April 11, 2023, 11:15am UTC](https://community.glideapps.com/t/how-to-auto-calculate-one-of-the-2-fields-amount-and-balance-to-update-based-on-the-value-in-another/59365/10 "2023-04-11T11:15:34Z")

</div>

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