Getting a periodic report with all subaccounts rolled up into a higher account

87 views
Skip to first unread message

MN

unread,
May 14, 2020, 4:44:50 PM5/14/20
to Ledger
Hi,

Say I have the account Expense:Entertainment.

Under it I have:

Expense:Entertainment:Movies
Expense:Entertainment:Travel
Expense:Entertainment:Hobbies

I want a report of how much I spent on Expense:Entertainment overall for each year. It shouldn't show me all the subaccounts, but their amounts shouldn't be ignored.

So if, for 2019, Expense:Entertainment had $100 and the other three categories each had $50, it should show it as $250 for Expense:Entertainment for the whole year.

I can't seem to find a way to do this in Ledger. I've tried:

ledger -Y reg "^Expense:Entertainment$"  --period-sort "(amount)"

But this gives just the amounts in Expense:Entertainment

I also tried:

ledger -Y reg ^Expense:Entertainment --depth 2 --period-sort "(amount)"

This is a bit better, but it doesn't quite do it. In the first column it shows only the amount for Expense:Entertainment. In the second column it has all the subaccounts, but the problem is it is cumulative:

15-Jan-01 - 15-Dec-31           Expense:Entertainment      4.30 USD   402.92 USD
16-Jan-01 - 16-Dec-31           Expense:Entertainment   1233.76 USD  2687.10 USD
17-Jan-01 - 17-Dec-31           Expense:Entertainment     80.23 USD  2800.33 USD
18-Jan-01 - 18-Dec-31           Expense:Entertainment      9.89 USD  2949.82 USD

Also, just on the side - I noticed this command:

ledger reg Expense:Entertainment --depth 2 --period yearly

Gives slightly different values in the second column. Not sure why.

The other problem with this is that it starts in 2015, when I have entries prior to 2015 (but they appear only in subaccounts, and not the parent Expense:Entertainment account).

Any help would be appreciated.

MN

unread,
May 14, 2020, 5:56:18 PM5/14/20
to Ledger
Seems this is not possible based on:


And there is a pull request from 2 days ago:


I hope this gets implemented. The request has been there since 2013 :-(

o1bigtenor

unread,
May 14, 2020, 9:09:07 PM5/14/20
to Ledger
Greetings

I do quite a bit of this. Sometimes I can have a very large number of
sub accounts that all
feed into one 'major' account.

You have just used account 'names' where I added numbers (a LOT of numbers).
Likely you've seen various 4 digit codes - - - - slightly different
but both the USA
and canuckistan use GIFI (IIRC general index of financial information)
codes for business.
I have extended that numbering scheme (adding more digits) so that I
can do exactly
what you are doing. Currently I have 20 different account numbers for
'entertainment'.
So I'm a 'little' anal - - - - grin - - - but I can tell you have much
money was used in each
form of entertainment and then I have a query where the whole basket
of stuff is
accumulated.

There may be a way of doing this when the 'accounts' are 'names'
instead of numbers
but the numbers are quite (the first 4 anyway) standardized for
business so I wen t
that way. For you to change your system would likely be some work but
on the plain
text program I'm working with there are search and replace functions
(work well and
are very easy) that might be one way of doing things - - - - ymmv!

Further questions cheerfully entertained!

Regards

Michael Cooper

unread,
May 15, 2020, 2:48:42 AM5/15/20
to Ledger
For this purpose, I use balance with the --group-by option, like this:

ledger balance Expense:Entertainment --depth 2 --group-by 'format_date(date, "%Y-%m")'

That would produce a series of balances grouped by month. You could also use "%Y" as the format string to get grouped by year, or many other things.

-Mythmon

--

---
You received this message because you are subscribed to the Google Groups "Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ledger-cli/6ec1ac43-7bf6-4f3f-b104-eb9b6989bcc8%40googlegroups.com.

Jasel17212

unread,
Jul 12, 2020, 9:48:51 AM7/12/20
to Ledger
I believe this will produce the summary output you're looking for:

ledger reg ^Expense:Entertainment --yearly --empty --collapse --period 2020
Reply all
Reply to author
Forward
0 new messages