Dataview Table: Summing a column

The queries below work in local tests (see screenshot).

The WHERE file.folder = this.file.folder would need to be changed to your FROM statement.

Used these starting points:

# D1
```dataview
TABLE frequency, date, amount, type
WHERE contains(frequency, "monthly") 
WHERE file.folder = this.file.folder 
SORT default(sendout, "") desc
```
# D2
```dataview
TABLE WITHOUT ID sum(map(rows, (r) => default(r.amount, 0))) AS "Total Price"
WHERE file.folder = this.file.folder 
GROUP BY true
```
# D3
```dataviewjs
const amounts = await dv.query(`
TABLE
  amount, frequency, date, type
WHERE file.folder = this.file.folder 
WHERE number(amount)
`)

if ( amounts.successful ) {
  const sum = amounts.value.values
    .map(a => a[1])
    .reduce((tmp, curr) => tmp + curr, 0)

  amounts.value.values.push(["<span style='float: right'><strong>Total:</strong></span>", sum])
  dv.table(amounts.value.headers, amounts.value.values) 
} else
  dv.paragraph("~~~~\n" + amounts.error + "\n~~~~")
```

3 Likes