# Need help with a calculation please

**URL:** <https://community.glideapps.com/t/need-help-with-a-calculation-please/80556>\
**Category:** Ask for Help\
**Created:** [March 7, 2025, 3:18am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556 "2025-03-07T03:18:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [March 7, 2025, 3:18am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/1 "2025-03-07T03:18:00Z")

</div>

Hi all. I need some help please as I want to perform a calculation but I think it will need to be done in javascript but I have no idea how to write javascript.

I have a table (below) that records weight for neonate kittens. What I would love to include is a fields that calculates the difference between the weight entered for the current row to the prior recorded weight for the same kitten. So, for example, for Fonzie, for the weight entered on 07/03, it is +16g compared the prior recorded weight on 06/03. The issue is 1) we may record more than one weight for the kitten per day (depends on how critical they are) and b), they may be entered out of order so couldn’t just say look back for the prior entry for this kitten. Mostly likely they would be entered in order, but they may not. And c), sometimes we may not record a weight.

The difference may be +/- and, ultimately, when we go to the paid version, I want create an automation that if it is - it will email the foster coordinator with an urgent alert… but that is down the line. Right now I just would love some help on how to code this - at least I assume it would need to be a javascript??

Thanks in anticipation 😺

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/4/4452aa327045dd9ba4ef0f448da18332b36b6703.png)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [March 7, 2025, 3:47am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/2 "2025-03-07T03:47:30Z")

</div>

You don’t need JavaScript, you can do it with a Query column as follows:

- Create a Query column in the same table, target the table, and apply the following filters:  
– CatsID is This row-\>CatsID  
– Date is before This row-\>Date  
– Weight is not empty
- Order the Query by Date in descending order
- Next add a Single Value column, target it at the Query column, and select first-\>Weight. This will give you the prior recorded weight for each cat.
- Now you can use a simple Math column to determine the difference (Weight - Single Value Weight)

Below is a video that demonstrates the general technique.

[![](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/0/c07e59897bed9d57245e47f85182182ad237b6b2.jpeg "Creating a Running Total with a Query Column 🏃 ♂️") ](https://www.youtube.com/watch?v=5YJ1QcQv78g)

---

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [March 7, 2025, 3:49am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/3 "2025-03-07T03:49:48Z")

</div>

Oh wow! Ok, cool! I will have a crack! Thanks so much!

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [March 7, 2025, 3:53am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/4 "2025-03-07T03:53:52Z")

</div>

oh, one thing I missed - to cater for the fact that you don’t always record a weight, add a 3rd filter condition to your Query:

- Weight is not empty

(I updated my earlier reply to reflect the above)

---

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [March 7, 2025, 4:12am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/5 "2025-03-07T04:12:07Z")

</div>

Thanks Darren. I’ve tried that but I’ve hit a snag in the Single Value column. I don’t have any option to select first\>Weight. Here is what I get:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/7/47c85463f614498c80668ee35b622f7e6b861886.png)

Which I assume is why my third column isn’t working as no WeightSort??

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

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [March 7, 2025, 4:28am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/6 "2025-03-07T04:28:24Z")

</div>

This is wrong ⬇

 ![CleanShot 2025-03-07 at 12.27.15@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/0/d0bdc140c7ee8587d30aabfbed6fd4ee6e4bf8fb.jpeg)

You need to target the Query column directly, not via the table. You should see it near the top of the list.

---

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [March 7, 2025, 4:51am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/7 "2025-03-07T04:51:12Z")

</div>

Thank you so much, Darren! I got it working! This is fabulous! I’m loving Glide and I’m only scratching the surface as I’m a complete newbie when it comes to all this stuff!

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/3/23dbc53b5b92f7676f5a173d97143ebbf1d76139.png)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [March 7, 2025, 5:52am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/8 "2025-03-07T05:52:45Z")

</div>

Nice, well done 👍

---

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [March 7, 2025, 7:02am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/9 "2025-03-07T07:02:47Z")

</div>

All thanks to your excellent instructions and patience.

---

<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:** [March 14, 2025, 7:03am UTC](https://community.glideapps.com/t/need-help-with-a-calculation-please/80556/10 "2025-03-14T07:03:17Z")

</div>

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