# Product of values in Array

**URL:** <https://community.glideapps.com/t/product-of-values-in-array/70710>\
**Category:** Ask for Help\
**Created:** [February 11, 2024, 8:08am UTC](https://community.glideapps.com/t/product-of-values-in-array/70710 "2024-02-11T08:08:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.pulse21](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/m.pulse21/32/70733_2.png) [@m.pulse21](https://community.glideapps.com/u/m.pulse21)\
**Post date:** [February 11, 2024, 8:08am UTC](https://community.glideapps.com/t/product-of-values-in-array/70710/1 "2024-02-11T08:08:17Z")

</div>

I am working on calculating Time Weighted Returns (TWR) in my app. The calculation starts by taking the % return (Daily) from each day and adding 1 to it. To calculate the TWR, you take that day’s DailyValue and multiply it with each day that proceeds it then less 1. So in a three day series the calculation would look like:  
(Daily1 + 1)_(Daily2 + 1)_(Daily3 + 1)-1

I have a column that already equals Daily + 1. I then created a query of the table on itself for any dates that match or are before the row’s date. Then I did a lookup to pull back all the Daily + 1 values that match. It is returning what I would expect.

The problem I’m trying to solve is how to calculate the product of the values in the resultant array.

Thanks for any help or ideas! 🙂

 ![Screenshot 2024-02-11 at 12.59.02 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/2/5271cb6f303349e73946ae2df151dcc0c0c2aa23.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:** [February 11, 2024, 8:34am UTC](https://community.glideapps.com/t/product-of-values-in-array/70710/2 "2024-02-11T08:34:25Z")

</div>

> [@m.pulse21](#):
>
> The problem I’m trying to solve is how to calculate the product of the values in the resultant array.

You should be able to use a Rollup-\>Sum and target it at the Lookup column. Be sure to target the Lookup column directly, and not via the table.

---

<div class="post-metadata">

**Author:** ![m.pulse21](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/m.pulse21/32/70733_2.png) [@m.pulse21](https://community.glideapps.com/u/m.pulse21)\
**Post date:** [February 11, 2024, 9:13am UTC](https://community.glideapps.com/t/product-of-values-in-array/70710/3 "2024-02-11T09:13:13Z")

</div>

Thanks for your quick reply @Darren_Murphy. Unfortunately I’m not looking for the sum of the values, I’m needing the product of the values.

If the arrays values were 2, 4, 6 I need my result to be 48. The rollup\>sum function will produce 12.

---

<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:** [February 11, 2024, 10:03am UTC](https://community.glideapps.com/t/product-of-values-in-array/70710/4 "2024-02-11T10:03:28Z")

</div>

oh, apologies - I misread.

hmm, the first thing that jumps into my head is to take a Joined List of the values via the Query, and feed that into a JavaScript column to do the calculation.

Something like the following:

```auto
const array = p1.split(', ').map(Number);
return array.reduce((accumulator, currentValue) => accumulator * currentValue);

```

![CleanShot 2024-02-11 at 18.02.52@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/3/4325943628632c830f6925c50e6b2a6271f5c2cc.png)

---

<div class="post-metadata">

**Author:** ![m.pulse21](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/m.pulse21/32/70733_2.png) [@m.pulse21](https://community.glideapps.com/u/m.pulse21)\
**Post date:** [February 11, 2024, 2:26pm UTC](https://community.glideapps.com/t/product-of-values-in-array/70710/5 "2024-02-11T14:26:21Z")

</div>

That worked splendidly! Thank you 🙂 I haven’t used a JavaScript column yet. I’ll have to dive into that more.
