Coding dataviewJS to help calculate my finances


What I’m trying to do

im trying to use Dataviewjs to organize my finances. im trying to create a note that will search my notes, subtract my bills and subscriptions from my income and show me the totals for each preferably in the form of a table although i don’t mind whatever. i don’t have a ton of javascript experience so its been trial and error with little progress

Things I have tried

ive tried using chatgpt to gerry-rig some code together but its not working but i dont know how to begin fixing it. any assistance would be much appreciated.

// Search for all files with #income, #debt, and #subscription tags and extract their values

const data = await dv.query(`
TABLE, number(income) AS Income, number(debt) AS Debt, number(subscription) AS Subscription
WHERE CONTAINS "#income" OR CONTAINS "#debt" OR CONTAINS "#subscription"

// Calculate the total income, total debt, total subscription, and the final total

if (data.successful) {
const totalIncome = data.value.values.reduce((sum, file) => sum + (file[1] || 0), 0)
const totalDebt = data.value.values.reduce((sum, file) => sum + (file[2] || 0), 0)
const totalSubscription = data.value.values.reduce((sum, file) => sum + (file[3] || 0), 0)
const finalTotal = totalIncome - totalDebt - totalSubscription


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