Summarizing calculated Values

What I’m trying to do

I am trying to set up an overview of my regular spendings.
I have created a template that I’m using for each spending as follows:

up:: [[wiederkehrende Ausgaben MOC]]
Tags:: #Finanzen/Ausgaben/regelmäßig #Finanzen/Kategorie
Betrag:: 0.00€
Frequenz:: 1
BetragMtl::`=number([[{{title}}]].Betrag)/number([[{{title}}]].Frequenz)`
BetragYrl::`=number([[{{title}}]].Betrag)/number([[{{title}}]].Frequenz)*12`
Verwendungszweck:: 
Empfänger:: 
IBAN:: 
Dauerauftrag:: nein / ja
Laufzeit:: 
Rücklagen:: -

# {{title}}

as you can see there are the “BetragMtl” and “BetragYrl” values that are calculated via dataview inline

these are reported by an overview-page that hosts a dataview table:

TABLE WITHOUT ID
 file.link as Was,
 Betrag,
 Frequenz as "Alle # Monate",
 Laufzeit as bis
 
FROM #Finanzen/Ausgaben/regelmäßig  and !"Extras/templates/Template - wiederkehrende Ausgaben"
SORT Laufzeit ASC

now I’m trying to get a SUM of BetragMtl a for easy comparing my monthly earnings vs spendings

Things I have tried

TABLE WITHOUT ID 
    sum(map(rows, (r) => default(r.BetragMtl, 0))) AS "Monatlich"
FROM #Finanzen/Ausgaben/regelmäßig and !"Extras/templates/Template - wiederkehrende Ausgaben"
GROUP BY true

now this actually works somehow with one note
but as soon as the second one comes in I’ll get the following message:

so I think that the inlines are processed at runtime rather than calculating the results and only then calculating the sum

in order to verify that I already modified the two notes so “Betrag” only contains number values and modified the sum-function to get the “Betrag” value. That works - so I’m sure it must be something with the “stacked” dataviews…

also tried my own modified version of smiggles’s DataviewJS solution from the Dataview sum of all prices in table - Help - Obsidian Forum

my modified version looks as follows:

let pages = dv
    .pages('#Finanzen/Ausgaben/regelmäßig and !"Extras/templates/Template - wiederkehrende Ausgaben"')

let totalPrice = pages.map((page, index) => [
		page.file.link,
        page.BetragMtl,
        page.BetragYrl
    ]);

totalPrice["values"][totalPrice.length] = [
    "***BetragMtl***",
    "",
    "",
    dv.func.default(dv.func.sum(pages.BetragMtl), 0),
];

dv.table(["Was", "Monatlich", "Jährlich", "Total"], totalPrice);

still the issue that the value is not displayed - but the error message…
any ideas?

Inline fields holds the query itself, and not the result of the query. This causes issues when you try to read it the value in another query.

You need to repeat the calculation in the second query before you’re able to use the value for summation.

Solution:

TABLE WITHOUT ID 
    sum(map(rows, (r) => default(r.Betrag/r.Frequenz, 0))) AS "Monatlich",
    sum(map(rows, (r) => default(r.Betrag/r.Frequenz*12, 0))) AS "Jährlich"
FROM #Finanzen/Ausgaben/regelmäßig and !"Extras/templates/Template - wiederkehrende Ausgaben"
GROUP BY true

thought it would work, but gives me

Dataview: Every row during final data extraction failed with an error; first 3:

        - No implementation found for 'number / null'

got it back to work… in one of the notes i accidentally removed the “Frequenz”… my bad

1 Like

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