Aggregate query which includes balance

37 views
Skip to first unread message

Oon-Ee Ng

unread,
Sep 21, 2018, 1:34:48 AM9/21/18
to bean...@googlegroups.com
I'm not sure if this is a bug or intended behaviour, so seeking advise here first.

SELECT QUARTER(date) as quarter, last(balance)
FROM date > 2017-12-31
WHERE account ~ 'Assets:Banking|Assets:Cash'
GROUP BY quarter
ORDER BY quarter, DESC

What it returns is the balances assuming that it starts at a balance of 0 on 2018-01-01 (which makes sense I guess) but what I'm looking for with the FROM date > 2017-12-31 is to only return results from that period of time. Something similar to what fava does when you place '2018' into the 'Time' box.

So for example if my banking accounts and cash had 5000 on the first of January and 2000 now, the query above would return -3000. I'd like it to return 2000 (which it does if I remove the FROM, but also returns all my 13 years of accounting history...)

Martin Blais

unread,
Sep 21, 2018, 1:43:31 AM9/21/18
to Beancount
Opening and closing periods is described here (apologies for the long document):

Simply filtering postings indeed ignores the (filtered) past.
Best is to use OPEN.

Replace 
  FROM date > <date>
with
  FROM OPEN ON <date>

This substitutes the past transactions with summarizing ones to bring the accounts to the same balance.




Reply all
Reply to author
Forward
0 new messages