Beanquery - Return the other account involved in a transaction

61 views
Skip to first unread message

Daniel González

unread,
Nov 12, 2022, 5:19:52 PM11/12/22
to Beancount
Hi,

I'm interested in querying an account for transactions made agains another account in particular. 

For example let's say I have:

2022-10-01 * "Gas bofa"
  Assets:BofA:Checking
  Expenses:Gas          40 USD

2022-10-02 * "Gas WF"
  Assets:WellsFargo:Checking
  Expenses:Gas          20 USD

2022-10-03 * "Gas WF"
  Assets:WellsFargo:Checking
  Expenses:Gas          40 USD

I would like to check my WF checking account for Gas expenses. This is, I would like to return only the last two transactions. 

More generally, I would also like be able to see in a query the other account agains which this transaction was made. Something like:

date,narration,account, counter-account (?), position (USD)
2022-10-01,Gas bofa,Assets:BofA:Checking,Expenses:Gas,-40
2022-10-02,Gas WF,Assets:WellsFargo:Checking,Expenses:Gas,-20
2022-10-03,Gas WF,Assets:WellsFargo:Checking,Expenses:Gas,-40

Is this possible?

Matthew Bafford

unread,
Nov 13, 2022, 8:07:31 AM11/13/22
to Beancount
There is no guarantee there will be only two accounts represented in a transaction. So this may result in multiple "other account" entries returned.

Given your inputs above the query and result is possible with beanquery :

    $ bean-query ./test.beancount 'select date, narration, account, other_accounts, number, currency where account ~ ":Gas" and joinstr(other_accounts) ~ "WellsFargo"' -f csv
    date,narration,account,other_accounts,number,currency
    2022-10-02,Gas WF,Expenses:Gas,Assets:WellsFargo:Checking,20,USD
    2022-10-03,Gas WF,Expenses:Gas,Assets:WellsFargo:Checking,40,USD

But if you have more complicated transactions with multiple expenses, you'll also potentially end up with rows with multiple accounts like this:

    2022-07-26,GasAndEat,Expenses:Gas,"Expenses:Food,Assets:WellsFargo:Checking",26.99,USD

Daniel González

unread,
Nov 13, 2022, 11:20:17 AM11/13/22
to Beancount
Thank you Matthew! I realize now that it's a supported option, I just couldn't find it in the documentation.
Reply all
Reply to author
Forward
0 new messages