I'm trying to make a query that would return networth over time. With a lot of experimentation, I've found that
SELECT year, month, last(balance) WHERE account ~ 'Assets|Liabilities'
works (using the examples/simple/basic.beancount ledger from the github repo):
year mo last(balance)
---- -- -------------------------------------------------------------------
2007 12 200.00 CAD 44152.81 USD
2008 1 30 AAPL {185.40 USD} 200.00 CAD 40465.46 USD
2008 2 200.00 CAD 100 EWJ {13.34 USD} 46904.98 USD
2008 3 200.00 CAD 100 EWJ {13.34 USD} 44995.59 USD
2008 4 200.00 CAD 100 EWJ {13.34 USD} 44995.59 USD
However, if I try to calculate the networth at the beginning of the period instead of the end, the following query:
SELECT year, month, first(balance) WHERE account ~ 'Assets|Liabilities'
returns absolute nonsense:
year mo first(balance)
---- -- -----------------------
2007 12 200.00 CAD
2008 1 200.00 CAD -212.61 USD
2008 2 200.00 CAD -425.22 USD
2008 3 200.00 CAD -637.83 USD
2008 4 640.00 CAD -637.83 USD
Admittedly I'm struggling to understand what the balance column actually does, but this behavior seems pretty unexpected.