Make "reg" output the account balance

122 views
Skip to first unread message

Ondřej Čertík

unread,
Nov 13, 2023, 1:40:27 PM11/13/23
to Ledger
Hi,

I am new to ledger. I would like the "reg" command print all the transactions and for each account individually print the total (cumulative) balance of that account at the point of the transaction. I opened up an issue here:


That explains all the details on an example, and contains a Python script that does this. It would be nice to do it using ledger itself.

Does anybody know how to do that?

Thanks,
Ondrej

John Wiegley

unread,
Nov 15, 2023, 2:41:17 PM11/15/23
to Ondřej Čertík, Ledger
>>>>> "OČ" == Ondřej Čertík <ond...@certik.us> writes:

OČ> Does anybody know how to do that?

Does something like `--display-total account.total` help?

John

Ondřej Čertík

unread,
Nov 15, 2023, 3:20:01 PM11/15/23
to John Wiegley, Ledger
It doesn't seem to show the correct totals. Consider:

test/input(master) $ python process.py
Date Name Account Amount Account Balance
2010/12/01 Checking balance Assets:Checking 1000.00 1000.00
2010/12/01 Checking balance Equity:Opening Balances -1000.00 -1000.00
2010/12/20 Organic Co-op Expenses:Food:Groceries 37.50 37.50
2010/12/20 Organic Co-op Expenses:Food:Groceries 37.50 75.00
2010/12/20 Organic Co-op Expenses:Food:Groceries 37.50 112.50
2010/12/20 Organic Co-op Expenses:Food:Groceries 37.50 150.00
2010/12/20 Organic Co-op Expenses:Food:Groceries 37.50 187.50
2010/12/20 Organic Co-op Expenses:Food:Groceries 37.50 225.00
2010/12/20 Organic Co-op Assets:Checking -225.00 775.00
2010/12/28 Acme Mortgage Liabilities:Mortgage:Principal 200.00 200.00
2010/12/28 Acme Mortgage Expenses:Interest:Mortgage 500.00 500.00
2010/12/28 Acme Mortgage Expenses:Escrow 300.00 300.00
2010/12/28 Acme Mortgage Assets:Checking -1000.00 -225.00
2011/01/02 Grocery Store Expenses:Food:Groceries 65.00 290.00
2011/01/02 Grocery Store Assets:Checking -65.00 -290.00
2011/01/05 Employer Assets:Checking 2000.00 1710.00
2011/01/05 Employer Income:Salary -2000.00 -2000.00
2011/01/14 Bank Assets:Savings 300.00 300.00
2011/01/14 Bank Assets:Checking -300.00 1410.00
2011/01/19 Grocery Store Expenses:Food:Groceries 44.00 334.00
2011/01/19 Grocery Store Assets:Checking -44.00 1366.00
2011/01/25 Bank Assets:Checking 5500.00 6866.00
2011/01/25 Bank Assets:Savings -5500.00 -5200.00
2011/01/25 Tom's Used Cars Expenses:Auto 5500.00 5500.00
2011/01/25 Tom's Used Cars Assets:Checking -5500.00 1366.00
2011/01/27 Book Store Expenses:Books 20.00 20.00
2011/01/27 Book Store Liabilities:MasterCard -20.00 -20.00
2011/04/25 Tom's Used Cars Expenses:Auto 5500.00 11000.00
2011/04/25 Tom's Used Cars Assets:Checking -5500.00 -4134.00
2011/04/27 Bookstore Expenses:Books 20.00 40.00
2011/04/27 Bookstore Assets:Checking -20.00 -4154.00
2011/12/01 Sale Assets:Checking 30.00 -4124.00
2011/12/01 Sale Income:Sales -30.00 -30.00

test/input(master) $ ledger -f demo.ledger reg --display-total account.total
10-Dec-01 Checking balance Assets:Checking $ 1,000.00 $ 1,000.00
Equity:Opening Balances $ -1,000.00 $ -1,000.00
10-Dec-20 Organic Co-op Expenses:Food:Groceries $ 37.50 $ 37.50
Expenses:Food:Groceries $ 37.50 $ 37.50
Expenses:Food:Groceries $ 37.50 $ 37.50
Expenses:Food:Groceries $ 37.50 $ 37.50
Expenses:Food:Groceries $ 37.50 $ 37.50
Expenses:Food:Groceries $ 37.50 $ 37.50
Assets:Checking $ -225.00 $ 1,000.00
10-Dec-28 Acme Mortgage Liabilities:Mortgage:Principal $ 200.00 $ 200.00
Expenses:Interest:Mortgage $ 500.00 $ 500.00
Expenses:Escrow $ 300.00 $ 300.00
Assets:Checking $ -1,000.00 $ 1,000.00
11-Jan-02 Grocery Store Expenses:Food:Groceries $ 65.00 $ 37.50
Assets:Checking $ -65.00 $ 1,000.00
11-Jan-05 Employer Assets:Checking $ 2,000.00 $ 1,000.00
Income:Salary $ -2,000.00 $ -2,000.00
11-Jan-14 Bank Assets:Savings $ 300.00 $ 300.00
Assets:Checking $ -300.00 $ 1,000.00
11-Jan-19 Grocery Store Expenses:Food:Groceries $ 44.00 $ 37.50
Assets:Checking $ -44.00 $ 1,000.00
11-Jan-25 Bank Assets:Checking $ 5,500.00 $ 1,000.00
Assets:Savings $ -5,500.00 $ 300.00
11-Jan-25 Tom's Used Cars Expenses:Auto $ 5,500.00 $ 5,500.00
Assets:Checking $ -5,500.00 $ 1,000.00
11-Jan-27 Book Store Expenses:Books $ 20.00 $ 20.00
Liabilities:MasterCard $ -20.00 $ -20.00
11-Apr-25 Tom's Used Cars Expenses:Auto $ 5,500.00 $ 5,500.00
Assets:Checking $ -5,500.00 $ 1,000.00
11-Apr-27 Bookstore Expenses:Books $ 20.00 $ 20.00
Assets:Checking $ -20.00 $ 1,000.00
11-Dec-01 Sale Assets:Checking $ 30.00 $ 1,000.00
Income:Sales $ -30.00 $ -30.00

$ ledger -f demo.ledger reg Assets:Checking
10-Dec-01 Checking balance Assets:Checking $ 1,000.00 $ 1,000.00
10-Dec-20 Organic Co-op Assets:Checking $ -225.00 $ 775.00
10-Dec-28 Acme Mortgage Assets:Checking $ -1,000.00 $ -225.00
11-Jan-02 Grocery Store Assets:Checking $ -65.00 $ -290.00
11-Jan-05 Employer Assets:Checking $ 2,000.00 $ 1,710.00
11-Jan-14 Bank Assets:Checking $ -300.00 $ 1,410.00
11-Jan-19 Grocery Store Assets:Checking $ -44.00 $ 1,366.00
11-Jan-25 Bank Assets:Checking $ 5,500.00 $ 6,866.00
11-Jan-25 Tom's Used Cars Assets:Checking $ -5,500.00 $ 1,366.00
11-Apr-25 Tom's Used Cars Assets:Checking $ -5,500.00 $ -4,134.00
11-Apr-27 Bookstore Assets:Checking $ -20.00 $ -4,154.00
11-Dec-01 Sale Assets:Checking $ 30.00 $ -4,124.00



For example, the `Assets:Checking` checking balance at the end is $ -4,124.00. The same number reported using my Python script:

2011/12/01 Sale Assets:Checking 30.00 -4124.00

But --display-total account.total reports:

11-Dec-01 Sale Assets:Checking $ 30.00 $ 1,000.00



Ondrej

John Wiegley

unread,
Nov 22, 2023, 2:44:22 PM11/22/23
to Ondřej Čertík, Ledger
>>>>> Ondřej Čertík <ond...@certik.us> writes:

>> Does something like `--display-total account.total` help?

> It doesn't seem to show the correct totals. Consider:

Hmm… this doesn’t seem like something that the ‘reg’ report will ever be able
to do, since it’s designed around a running total that reflects the direct
summation of the amounts displayed. What you want is almost like a
running-form version of the balance report. I don’t think Ledger has anything
like this built in.

John

Martin Michlmayr

unread,
Nov 22, 2023, 6:42:20 PM11/22/23
to ledge...@googlegroups.com, Ondřej Čertík
How about:
ledger reg --daily
It doesn't quite do what you want but I think it's the best there is
for now.

--
Martin Michlmayr
https://www.cyrius.com/

Ondřej Čertík

unread,
Nov 24, 2023, 2:19:08 AM11/24/23
to John Wiegley, Ledger
Yes, running-form balance report is one way to look at it. The algorithm for it is trivial, it's about 10 lines of Python code here: https://github.com/ledger/ledger/issues/2297. However it's probably more complicated to take into account all corner cases and integrate into ledger-cli.

Martin, thanks for the suggestion of "ledger reg --daily". It's not quite there, as you said.

I see now that the design of "reg" is to always have a running total of the amounts displayed. So it should probably be another command, or an option.

Ondrej
Reply all
Reply to author
Forward
0 new messages