Adding up different expenses and converting at original rate

53 views
Skip to first unread message

Martin Michlmayr

unread,
Dec 7, 2018, 11:13:13 AM12/7/18
to bean...@googlegroups.com
I have expenses in one currency (EUR) and want to convert all of them
to another (USD) **on the day** of the transaction.

This gives the correct result because I pass "date" to CONVERT():

beancount> SELECT sum(convert(position, "USD", date)) WHERE account ~ '^Assets:A';
sum_conver
----------
107.50 USD

But I'd like to see a "register" type view with each individual
transaction and the total. Unfortunately, the only way I can
figure out is to convert the whole balance to USD, which gives
a different result to converting each transaction on the original
date:

beancount> SELECT position, convert(balance, "USD", date) WHERE account ~ '^Assets:A';
position convert_ba
----------------- ----------
20 EUR 22.00 USD
45 EUR {1.14 USD} 74.10 USD
30 EUR {1.14 USD} 108.30 USD

How can I see 107.50 here?

I tried something like
SELECT position, SUM(convert(position, "USD", date)) WHERE account ~ '^Assets:A';
but sum(position) doesn't do what I want when I look at
each transaction separately.

Test case:

plugin "beancount.plugins.implicit_prices"

2000-01-01 open Assets:A
2000-01-01 open Assets:B

2018-12-05 * "Test 1"
Assets:A 20 EUR @ 1.10 USD
Assets:B

2018-12-06 * "Test 2"
Assets:A 45 EUR {1.14 USD} @ 1.14 USD
Assets:B

2018-12-07 * "Test 3"
Assets:A 30 EUR {1.14 USD}
Assets:B

--
Martin Michlmayr
https://www.cyrius.com/

Martin Blais

unread,
Dec 12, 2018, 12:58:46 AM12/12/18
to Beancount
This is a great use case.
I'm afraid this is beyond the current capabilities of the automatically generated "balance" column.
We'll have to save that one for the next version and think about a syntax that would allow one to create a balance column by referencing another column.
e.g.,

  SELECT position, SUM(convert(position, "USD", date)) as usd_amount, BALANCE(usd_amount) as usd_balance WHERE ...

Something like that.





--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/20181207161308.56ivkgujculalx7g%40jirafa.cyrius.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages