How to compute average monthly expenses?

10 views
Skip to first unread message

Marcin Borkowski

unread,
Jan 23, 2023, 12:04:08 AMJan 23
to Ledger
Hi all,

I try to follow the example from the manual and compute average monthly
expenses. Here is my example journal file:

--8<---------------cut here---------------start------------->8---
2022-01-01 Food
Expenses:Food 930.00 PLN
Assets:Cash

2022-02-01 Food
Expenses:Food 800.00 PLN
Assets:Cash

2022-03-01 Food
Expenses:Food 970.00 PLN
Assets:Cash
--8<---------------cut here---------------end--------------->8---

and here is what I do in command line:

--8<---------------cut here---------------start------------->8---
ledger -b 2022-01-01 -e 2022-04-01 --monthly --average balance -f myfile

-450.00 PLN Assets:Cash
450.00 PLN Expenses:Food
--------------------
0
--8<---------------cut here---------------end--------------->8---

What is going on here? (Obviously, I expected 900 PLN monthly average.)
Even more unexpectedly, when I use -p "last year", the result is exactly
the same (and I would expect 300 PLN then).

I use Ledger 3.2.1-20200518.

TIA,

--
Marcin Borkowski
http://mbork.pl

Stanko Trček

unread,
Jan 23, 2023, 3:12:44 PM (13 days ago) Jan 23
to Ledger
How about this ?

ledger -f data.txt --monthly --average  register Expenses

ponedeljek, 23. januar 2023 ob 06:04:08 UTC+1 je oseba Marcin Borkowski napisala:

Marcin Borkowski

unread,
Jan 23, 2023, 3:51:47 PM (13 days ago) Jan 23
to ledge...@googlegroups.com

On 2023-01-23, at 21:12, Stanko Trček <stanko...@gmail.com> wrote:

> How about this ?
>
> ledger -f data.txt --monthly --average register Expenses

Ah, I think this works. I'll perform a few more experiments. Thanks!

Best,

John Wiegley

unread,
Jan 23, 2023, 5:58:46 PM (13 days ago) Jan 23
to Marcin Borkowski, Ledger
>>>>> "MB" == Marcin Borkowski <mb...@mbork.pl> writes:

MB> What is going on here? (Obviously, I expected 900 PLN monthly average.)
MB> Even more unexpectedly, when I use -p "last year", the result is exactly
MB> the same (and I would expect 300 PLN then).

I'm not sure that "--average" has ever done what everyone expects in the
balance report.

John

o1bigtenor

unread,
Jan 23, 2023, 6:05:46 PM (13 days ago) Jan 23
to ledge...@googlegroups.com, jwie...@gmail.com
That - sir - - - -begs the question - - - what is 'average' supposed to do?

TIA

John Wiegley

unread,
Jan 23, 2023, 7:07:35 PM (13 days ago) Jan 23
to o1bigtenor, ledge...@googlegroups.com
>>>>> o1bigtenor <o1big...@gmail.com> writes:

> That - sir - - - -begs the question - - - what is 'average' supposed to do?

Average just takes the number of entries in a group, and divides the total by
the count. Here's the implementation:

OPTION_(report_t, average, DO() { // -A
OTHER(empty).on(whence);
OTHER(display_total_)
.on(whence, "count>0?(display_total/count):0");
});

Which means that `--average` is just a short-hand for:

--empty --display-total "count>0?(display_total/count):0"

John

Marcin Borkowski

unread,
Jan 24, 2023, 2:40:47 AM (13 days ago) Jan 24
to ledge...@googlegroups.com, o1bigtenor
Thanks for the answer, but that still does not explain the "450" figure
for me. Of course, the total is 2700, so I assume Ledger divided it by
6 -- but why 6?

(Also, since I've decided to finally finish my booklet on accounting
with Ledger, expect more questions soon;-) -- hope that's ok with
you...)

Best,

Ihor Radchenko

unread,
Jan 25, 2023, 5:23:33 PM (11 days ago) Jan 25
to Marcin Borkowski, ledge...@googlegroups.com, o1bigtenor
Marcin Borkowski <mb...@mbork.pl> writes:

>> Average just takes the number of entries in a group, and divides the total by
>> the count. Here's the implementation:

What about the last time group where the expenses may not yet represent
the value at the end of the month?

P.S. I am wondering why I am only seeing Marcin's emails.

--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

John Wiegley

unread,
Jan 27, 2023, 4:47:46 PM (9 days ago) Jan 27
to Marcin Borkowski, ledge...@googlegroups.com, o1bigtenor
>>>>> "MB" == Marcin Borkowski <mb...@mbork.pl> writes:

MB> Thanks for the answer, but that still does not explain the "450" figure
MB> for me. Of course, the total is 2700, so I assume Ledger divided it by 6
MB> -- but why 6?

Hmmm.. good question, I wonder where that count is coming from.

MB> (Also, since I've decided to finally finish my booklet on accounting with
MB> Ledger, expect more questions soon;-) -- hope that's ok with you...)

Yes, very OK with me!

John
Reply all
Reply to author
Forward
0 new messages