Register report with depth limit and sub-totaling

459 views
Skip to first unread message

Evgeny Panasyuk

unread,
Jun 13, 2016, 1:36:41 AM6/13/16
to Ledger
Hello, all!

Let's start with small example:
; example.ledger

2016/05/31 car
    expenses
:car:gas      100$
    expenses
:car:repair  1000$
    expenses
:other          5$
    assets
:cash

It is possible to limit level of balance report to depth=2 and get following report:
ledger -f example.ledger bal expenses --depth 2
               
1105$  expenses
               
1100$    car
                 
5$    other
--------------------
               
1105$
As you can see, for each second level account we get subtotal of all child accounts, i.e. expenses:car = expenses:car:gas + expenses:car:repair

I would like to get similar effect for register monthly report. For instance regular register report shows:
ledger -f example.ledger reg expenses -M
16-May-01 - 16-May-31           expenses:car:gas               100$         100$
                                expenses
:car:repair           1000$        1100$
                                expenses
:other                   5$        1105

I do not want such detailed report, what I want is to limit depth to 2 and get subtotals for each second level account, similar to above balance report. Something like:
ledger -f example.ledger reg expenses -M
16-May-01 - 16-May-31           expenses:car                  1100$        1100$
                                expenses
:other                   5$        1105$

How to achieve this?

Simon Michael

unread,
Jun 13, 2016, 9:18:53 AM6/13/16
to ledge...@googlegroups.com
On 5/31/16 7:37 AM, Evgeny Panasyuk wrote:
> I do not want such detailed report, what I want is to limit depth to 2 and
> get subtotals for each second level account, similar to above balance
> report. Something like:
> ledger -f example.ledger reg expenses -M
> 16-May-01 - 16-May-31 expenses:car 1100$
> 1100$
> expenses:other 5$
> 1105$
>
> How to achieve this?

You could use hledger register:

ledger -f example.ledger print expenses | hledger -f- reg expenses -M
--depth 2


Evgeny Panasyuk

unread,
Jun 13, 2016, 6:44:38 PM6/13/16
to Ledger

How to achieve this?

I found on web that it is possible to achieve this with balance report plus special --group-by format:
; example2.ledger

2016/04/30 car
    expenses
:car:gas      200$
    expenses
:car:repair   500$
    expenses
:other         50$
    assets
:cash

2016/05/31 car
    expenses
:car:gas      100$
    expenses
:car:repair  1000$
    expenses
:other          5$
    assets
:cash

ledger -f example2.ledger bal --group-by 'format_date(date, "%Y-%m")' --depth 2 expenses
2016-04
               
750$  expenses
               
700$    car
                 
50$    other
--------------------
               
750$

2016-05

Chris Bennett

unread,
Jun 26, 2016, 7:25:33 AM6/26/16
to Ledger
Hey, I was trying to solve this yesterday , failed to find a solution, and then today I started reviewing the list out of habit and saw your post.  The group-by works perfectly :)  Thanks!

Chris

--

---
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.
For more options, visit https://groups.google.com/d/optout.

Evgeny Panasyuk

unread,
Jun 26, 2016, 4:37:35 PM6/26/16
to Ledger
 26 June 2016 г., 14:25:33 UTC+3 Chris Bennett :
Hey, I was trying to solve this yesterday , failed to find a solution, and then today I started reviewing the list out of habit and saw your post.  The group-by works perfectly :)  Thanks!


Glad that it was useful for you! Perhaps this example should be added to manual.

Also, group-by description in manual looks outdated:
--group-by EXPR

Group transactions together in the register report. EXPR can be anything, although most common would be payee or commodity.  The tags() function is also useful here.

It talks about register report only, while it does work for balance report too.

Best Regards,
Evgeny
Reply all
Reply to author
Forward
0 new messages