RFC: Make --depth in register report collapse sub-accounts

43 views
Skip to first unread message

Rahix

unread,
Jun 21, 2020, 9:46:15 AM6/21/20
to Ledger
Hello!

I made a PR with an implementation of this feature on GitHub [1] but was
asked to propose it here as well. This means you can actually already try
it out if this interests you. Here is what my proposed change does:

Right now (as of ledger 3.2.1), the `--depth` option in register reports
'cuts off' postings with a deeper level than the specified one. This
means any postings to subaccounts will not be accounted for in the
'amount' column. They will however still be added into the 'total'
column.

In my opinion, this isn't really a useful feature as it stands and the
report is quite unintuitive (adding all amounts does not yield the total).
So instead, my PR changes the behavior as follows:

`--depth` now 'collapses' all subaccounts up to the given depth. This
means any postings to subaccounts will be summed and added to the account
of the given depth. The outcome is that 'amount' and 'total' columns are
in agreement again (adding all 'amount's yields the final 'total') and no
postings are unaccounted for in the 'amount' column.

To visualize this, here is an example. The following register report:

$ ledger reg ^Expenses
20-May-13 Test Expenses:AA:BB 3.00 EUR 3.00 EUR
Expenses:AA 3.00 EUR 6.00 EUR
20-May-14 Test Expenses:AA:BB:CC 2.00 EUR 8.00 EUR
Expenses:DD 4.00 EUR 12.00 EUR

could, with this change implemented, be collapsed to the second level like
this:

$ ledger reg ^Expenses --depth 2
20-May-13 Test Expenses:AA 6.00 EUR 6.00 EUR
20-May-14 Test Expenses:AA 2.00 EUR 8.00 EUR
Expenses:DD 4.00 EUR 12.00 EUR

Note how the total is always the previous total + the amount. Without
this change, you'd get a report like this:

$ ledger reg ^Expenses --depth 2 # The old behavior
20-May-13 Test Expenses:AA 3.00 EUR 6.00 EUR
20-May-14 Test Expenses:DD 4.00 EUR 12.00 EUR

As you can see, in the first line, the total is suddenly 6 even though the
amount is only 3. And in the second line, the total again jumps by more
than what the amount would suggest.

In addition to fixing this inconsistency, this would also bring the
behavior of `--depth` in register reports more in line with what `--depth`
does for balance reports. There, it also doesn't cut off subaccounts but
accumulates their balances in the account of the given depth.

(Sidenote: The existing `-n`/`--collapse` option does what would now be
equivalent to `--depth 0`)

I'd be happy to get some feedback on this!

[1]: https://github.com/ledger/ledger/pull/1901
--
Rahix

Henrik Danielsson

unread,
Jun 21, 2020, 10:49:39 AM6/21/20
to ledge...@googlegroups.com
Den sön 21 juni 2020 kl 15:46 skrev Rahix <ra...@rahix.de>:
> Right now (as of ledger 3.2.1), the `--depth` option in register reports
> 'cuts off' postings with a deeper level than the specified one. This
> means any postings to subaccounts will not be accounted for in the
> 'amount' column. They will however still be added into the 'total'
> column.

I welcome this change very much!
A posting like "Expenses:Car:Fuel" will currently not even be included
in output or the total if it is the last posting and "--depth 2" is
used.
I've verified this change fixes that by listing it as "Expenses:Car"
which makes much more sense to me.

> In my opinion, this isn't really a useful feature as it stands and the
> report is quite unintuitive (adding all amounts does not yield the total).

Fully agree! I've been trying to use this for quite some time to
quickly try to figure out the totals for many of my higher level
accounts but have had to resort to doing them one by one because the
numbers were almost always off by some amount.

> In addition to fixing this inconsistency, this would also bring the
> behavior of `--depth` in register reports more in line with what `--depth`
> does for balance reports. There, it also doesn't cut off subaccounts but
> accumulates their balances in the account of the given depth.

This also appears to fix it https://github.com/ledger/ledger/issues/987.

Edwin Stearns

unread,
Jun 22, 2020, 9:30:31 AM6/22/20
to Ledger
This change would make —depth much more intuitive for me.

Rahix

unread,
Jun 22, 2020, 4:39:36 PM6/22/20
to ledge...@googlegroups.com

Rahix

unread,
Jun 22, 2020, 4:39:36 PM6/22/20
to ledge...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages