Thank you very much, this was really helpful.
I had to tweak it a bit and see how it actually works as I gather more reading.
Let's begin with the issue, using Income:Power as a positivi amount gave a strange balance sheet, flipping the power meter reading fixed it.
2024-03-01 * "Power meter reading for the whole complex"
Assets:Water 100 MQ @@ 200 KWH
Income:Power
Now that I sorted this out, I realized that the query was using the last available price for each pair instead of the price of that day, this was fixed adding the date parameter to each convert call.
At this point I realized that this was really error prone, 'case a missing price will have screwed up all my reports so I decided to track water with price and use balance directives to check the meters values.
plugin "beancount.plugins.auto_accounts"
option "operating_currency" "EUR"
2024-05-15 * "Initial water meter reading"
Expenses:Building1 1 MQ @ 0 KWH ; paid by the owner
Expenses:Building2 0 MQ @ 0 KWH
Expenses:Building3 0 MQ @ 0 KWH
Income:Power
2024-05-16 balance Expenses:Building1 1 MQ
2024-05-16 balance Expenses:Building2 0 MQ
2024-05-16 balance Expenses:Building3 0 MQ
2024-05-30 * "May water/power readings"
Expenses:Building1 0 MQ @ 0 KWH
Expenses:Building2 0 MQ @ 0 KWH
Expenses:Building3 1 MQ @ 0.6 KWH
Income:Power
2024-06-01 balance Income:Power -0.6 KWH
2024-06-01 balance Expenses:Building1 1 MQ
2024-06-01 balance Expenses:Building2 0 MQ
2024-06-01 balance Expenses:Building3 1 MQ
2024-06-11 ! "Fake reading"
Expenses:Building1 1.0 MQ @ 0.6 KWH
Expenses:Building2 3.0 MQ @ 0.6 KWH
Expenses:Building3 1.0 MQ @ 0.6 KWH
Income:Power
9999-12-31 balance Assets:Water 0 MQ ; make sure we are not leaking water
2024-05-15 price KWH 0 EUR
2024-05-30 price KWH 0.25 EUR ; cost of each KWH
And now the new queries:
Report month-by-month
select date, leaf(account) as building,
position as water, weight as kWh,
convert(weight, 'EUR', date) as payment
from year = 2024 where account ~ 'Expense'
Yearly report:
select leaf(account) as building,
sum(position) as water,
sum(weight) as kwh,
sum(convert(weight, 'EUR', date)) as payment
from year = 2024 where account ~ 'Expense'
group by leaf(account)
I'm quite happy with the result, as I can do a balance sheet to see the meter values, and extract those useful reports. My only concern is that will not be possible to find a missing KWH/EUR price unless there is a way to force convert to find an exact price for the date or fail.
Thank you very much again,
Alessio