Sum Values In a Column

What I’m trying to do

I want to sum all the values in the “Preço” column, but I don’t have any ideas of how I’m going to do that. I’m almost a total noob when it comes to coding.

TABLE WITHOUT ID as "Despesa", "R$ " + Preço as "Preço"
from "Dados/Despesas"
sort Preço, asc

This is the code that I used to create this dataview table.

Perhaps there’s a simpler way to do this (maybe even in DQL), but the code below works.

(You need to enable DataviewJS in Dataview settings)

const rows = dv.pages('"Dados/Despesas"').sort(a => => [, "R$ "+ a["Preço"]])
const total = Array.from(dv.pages('"Dados/Despesas"')).map(a => a["Preço"]).reduce((s, a) => s + a, 0);
let rowsArray = Array.from(rows)
rowsArray.push(["Total", "R$ " + total])
dv.table(["Despesa", "Preço"], rowsArray)
1 Like

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