Beancount queries¶
Create alias:
Accounts¶
List all know acconts:
List all uses account in year, filter by regex:
Account Balances¶
Balances at the end of the year:
Transaction totals for given year:
Beware: OPEN ON .. CLOSE ON adds an Opening balance transaction with
the balance on the account before the time span!
The total not the same as the query above!
Balance totals in 1 number:
Balance until given date:
Income total
Net profit
SELECT sum(cost(position)) as income FROM year = 2018 WHERE account ~ 'Income:Privat|Expenses:Privat'
Show income with metadata mwst = 19:
SELECT account, sum(position) FROM year = 2020 \
WHERE account ~ 'Income' AND any_meta('mwst') = '19'
Find amounts¶
SELECT * WHERE Number = 3.8
SELECT date,description,account,position WHERE number = 229.06
SELECT date,description,account,position FROM year = 2020 \
WHERE account ~ '^Expenses' AND number > 800
Journal entries / list transactions¶
See links section below for a SQL query that is similar to a JOURNAL query,
but contains more fields like i.e. links!
From the mailing list thread:
FROM can be used only with transaction columns and WHERE can be used only with posting columns.
JOURNAL "Expenses" AT COST FROM year = 2019
JOURNAL 'Assets' FROM NOT narration ~ 'foo'
JOURNAL 'Assets' FROM NOT narration ~ 'foo' AND year = 2014
Search for narration (description):
Date ranges:
JOURNAL FROM OPEN on 2014-01-01 CLOSE on 2015-01-01
JOURNAL "Assets" FROM CLOSE on 2021-01-14
JOURNAL 'Expenses' FROM year >= 2024
Show transaction after a given date:
Calculate total from date range:
SELECT account, sum(position) FROM OPEN ON 2021-09-01 CLOSE ON 2022-09-01 \
WHERE account ~ "Income|Expenses" GROUP BY 1 ORDER BY 1
Include transaction flag:
Show unverified transactions:
Sum of transactions¶
Generate csv file with sum of income/expenses for date range:
SELECT account, sum(position) \
FROM OPEN ON 2021-09-01 CLOSE ON 2022-09-01 \
WHERE account ~ "Income|Expenses" GROUP BY 1 ORDER BY 1;
Tags¶
#spikes: for marking/excluding spikes in the balance sheet
bq "SELECT date,description,account,position,tags WHERE 'spike' in tags" | \
grep -Ev 'Assets' | sed 's/ spike//'
Flags¶
Handling of flags in the lexer:
The lexer recognizes the
!&#?%PSTCURMcharacters as flags
Default txn flag will be evaluated as * !
Links¶
Metadata¶
Transaction metadata:
SELECT date,description,account,position,tags WHERE any_meta('mwst') = '19'
SELECT date, description, position, balance
WHERE any_meta('invoice') = '200' and ('payment' in tags)
Account meatadata:
Print journal entries matching a query: