Trying to sum elements of a list with reduce()

What I’m trying to do

In bases, I have one property that is a list of numbers. I’m trying to add/sum all the elements from that list into an other property with a formula.
For instance I have a “Costs” list: [10, 10, 20], the expected result from the formula would be: 40.

Things I have tried

I saw that a reduce() function was added to lists in version 1.10.0, but I can’t make it work, and didn’t find any documentation or exemple.

Hi.

This might not be the best solution, but it works in a local test file:

---
list:
  - 10
  - 10
  - 20
---

```base
formulas:
  sum: list.filter(value).reduce(number(value) + acc, 0)
views:
  - type: table
    name: Table
    filters:
      and:
        - file.name == this.file.name
    order:
      - file.name
      - formula.sum
    columnSize:
      formula.sum: 71

```

2 Likes

Yes it works! Thanks!
I’m still not sure to grasp the syntax of base.
Where would be the best place to learn it?

1 Like

Hi.

I only use the forum and the Obsidian help pages. My coding ‘knowledge’ is essentially zero.