hledger icon indicating copy to clipboard operation
hledger copied to clipboard

Is there a way to make register show only the final result for each transaction?

Open LaurenzWiskott2 opened this issue 4 years ago • 14 comments

Hello!

When using the register command I find it oft annoying that register calculates the intermediate result for each posting in a transaction. Often there are balancing postings, one subtracts 100€ the other one adds it again. When I try to follow the amount over time, I have a lot of meaningless ups and downs. Here is a dumb example register.ledger illustrating the point:

2021-01-01 A
    account:a                                                                 40 €
    account:b                                                               -120 €
    account:c                                                                 60 €
    external

2021-02-01 B
    account:a                                                                -50 €
    account:b                                                               +600 €
    account:c                                                               -560 €
    external

2021-03-01 B
    account:a                                                                 70 €
    account:b                                                                -30 €
    account:c                                                                 10 €
    external

Assume I want to know how my account develops over time, but I don't care so much about the subpostings a, b, and c, so I can run the command hledger -f register.ledger reg account and get:

2021-01-01 A                    account:a                     40 €          40 €
                                account:b                   -120 €         -80 €
                                account:c                     60 €         -20 €
2021-02-01 B                    account:a                    -50 €         -70 €
                                account:b                    600 €         530 €
                                account:c                   -560 €         -30 €
2021-03-01 B                    account:a                     70 €          40 €
                                account:b                    -30 €          10 €
                                account:c                     10 €          20 €

I find it very hard to review such an output in any meaningful way. I would much rather like to have something like:

2021-01-01 A                    account:a                     40 €
                                account:b                   -120 €
                                account:c                     60 €         -20 €
2021-02-01 B                    account:a                    -50 €
                                account:b                    600 €
                                account:c                   -560 €         -30 €
2021-03-01 B                    account:a                     70 €
                                account:b                    -30 €
                                account:c                     10 €          20 €

I have tried hledger -f register.ledger reg account --depth 1 but that only results in:

2021-01-01 A                    account                       40 €          40 €
                                account                     -120 €         -80 €
                                account                       60 €         -20 €
2021-02-01 B                    account                      -50 €         -70 €
                                account                      600 €         530 €
                                account                     -560 €         -30 €
2021-03-01 B                    account                       70 €          40 €
                                account                      -30 €          10 €
                                account                       10 €          20 €

while I was hoping it does something like:

2021-01-01 A                    account                      -20 €         -20 €
2021-02-01 B                    account                      -10 €         -30 €
2021-03-01 B                    account                       50 €          20 €

I guess you get the point. Can anybody help me with this. What would be the hledger way to do what I am looking for?

If there is no good way to do it, please consider this a feature request for an option that either suppresses intermediate results or displays them in a faint color or so. Maybe one could define the color of the intermediate outputs and customize the output that way.

I am using hledger 47b5b6b.

LaurenzWiskott2 avatar Dec 07 '21 20:12 LaurenzWiskott2

aregister ? It shows one line per transaction.

$ hledger areg account
Transactions in account and subaccounts:
2021-01-01 A                    external                     -20 €         -20 €
2021-02-01 B                    external                     -10 €         -30 €
2021-03-01 B                    external                      50 €          20 €

simonmichael avatar Dec 07 '21 20:12 simonmichael

Thanks for the very fast reply. Sure, that works and solves the toy problem. I see I have made a poor translation into a toy example of what I really want to do. Assume the file reads like

2021-01-01 A
    account                                                                 40 €
    bccount                                                               -120 €
    cccount                                                                 60 €
    external

2021-02-01 B
    account                                                                -50 €
    bccount                                                               +600 €
    cccount                                                               -560 €
    external

2021-03-01 C
    account                                                                 70 €
    bccount                                                                -30 €
    cccount                                                                 10 €
    external

If I now run hledger -f register2.ledger areg "(account|bccount|cccount)" --depth 1 I get:

Transactions in account and subaccounts:
2021-01-01 A                           bccount, cccount, external           40 €          40 €
2021-02-01 B                           bccount, cccount, external          -50 €         -10 €
2021-03-01 C                           bccount, cccount, external           70 €          60 €

aregonly uses the first account. It does not work for me to combine several accounts. With reg it reads:

2021-01-01 A                           account                              40 €          40 €
                                       bccount                            -120 €         -80 €
                                       cccount                              60 €         -20 €
2021-02-01 B                           account                             -50 €         -70 €
                                       bccount                             600 €         530 €
                                       cccount                            -560 €         -30 €
2021-03-01 C                           account                              70 €          40 €
                                       bccount                             -30 €          10 €
                                       cccount                              10 €          20 €

LaurenzWiskott2 avatar Dec 07 '21 21:12 LaurenzWiskott2

Sorry @LaurenzWiskott2 but I'm still not clear on the exact goal. There is also chat which might work better ?

simonmichael avatar Dec 07 '21 21:12 simonmichael

The closest I could get so far is with hledger -f register2.ledger bal "(account|bccount|cccount)" -M --transpose --historic

Ending balances (historical) in 2021Q1:

            || account  bccount  cccount |       
============++===========================+=======
 2021-01-31 ||    40 €   -120 €     60 € | -20 € 
 2021-02-28 ||   -10 €    480 €   -500 € | -30 € 
 2021-03-31 ||    60 €    450 €   -490 € |  20 € 

OK, I'll go to the chat.

LaurenzWiskott2 avatar Dec 07 '21 21:12 LaurenzWiskott2

Whenever I want a less detailed register report I use --daily in combination with depth limiting. This is lossy to some extent, but might be good enough for your use case?

Xitian9 avatar Dec 07 '21 21:12 Xitian9

https://hledger.org/support.html leads to

Resource not found 404

The requested resource could not be found.

LaurenzWiskott2 avatar Dec 07 '21 21:12 LaurenzWiskott2

Sorry, my mistake. I meant https://hledger.org/discuss.html .

I think you want a register report, with one line per transaction, but spanning multiple accounts. For that I agree with @Xitian9's suggestion, eg how about this ?:

$ hledger reg "(account|bccount|cccount)" -0 -D
2021-01-01   ...                                             -20 €         -20 €
2021-02-01   ...                                             -10 €         -30 €
2021-03-01   ...                                              50 €          20 €

simonmichael avatar Dec 07 '21 21:12 simonmichael

Thanks for this suggestions.

Whenever I want a less detailed register report I use --daily in combination with depth limiting. This is lossy to some extent, but might be good enough for your use case?

Yes, this would work for the first example. But for the second, hledger -f register2.ledger reg "(account|bccount|cccount)" --daily --depth 1 results in

2021-01-01   account                                40 €          40 €
             bccount                              -120 €         -80 €
             cccount                                60 €         -20 €
2021-02-01   account                               -50 €         -70 €
             bccount                               600 €         530 €
             cccount                              -560 €         -30 €
2021-03-01   account                                70 €          40 €
             bccount                               -30 €          10 €
             cccount                                10 €          20 €

as before. I think the point is that the accounts I want to combine are not within one branch.

LaurenzWiskott2 avatar Dec 07 '21 21:12 LaurenzWiskott2

Sorry, my mistake. I meant https://hledger.org/discuss.html .

I think you want a register report, with one line per transaction, but spanning multiple accounts. For that I agree with @Xitian9's suggestion, eg how about this ?:

$ hledger reg "(account|bccount|cccount)" -0 -D
2021-01-01   ...                                             -20 €         -20 €
2021-02-01   ...                                             -10 €         -30 €
2021-03-01   ...                                              50 €          20 €

Yes, that looks like a solution that might work. I only tried --depth 1, which didn't work. It didn't occur to me to use depth zero. I will see how far I'll get with that. Thank you two for your great and quick help. Fantastic.

PS: Still, I think an option to create a printout with all postings with values in the first column but only with the final result of each transaction in the second column would be useful.

LaurenzWiskott2 avatar Dec 07 '21 21:12 LaurenzWiskott2

I agree that a register variant like

2021-01-01 A                    account:a                     40 €
                                account:b                   -120 €
                                account:c                     60 €         -20 €
2021-02-01 B                    account:a                    -50 €
                                account:b                    600 €
                                account:c                   -560 €         -30 €
2021-03-01 B                    account:a                     70 €
                                account:b                    -30 €
                                account:c                     10 €          20 €

could be more readable sometimes. At other times, you do want to see the per-posting running totals. So we should ask ourselves, is it sufficiently useful to justify further complicating the CLI ? What UI (flag) would you propose ?

simonmichael avatar Dec 07 '21 21:12 simonmichael

Also, we should consider how that will look with multiple commodities in play.

simonmichael avatar Dec 07 '21 21:12 simonmichael

I agree that a register variant like

2021-01-01 A                    account:a                     40 €
                                account:b                   -120 €
                                account:c                     60 €         -20 €
2021-02-01 B                    account:a                    -50 €
                                account:b                    600 €
                                account:c                   -560 €         -30 €
2021-03-01 B                    account:a                     70 €
                                account:b                    -30 €
                                account:c                     10 €          20 €

could be more readable sometimes. At other times, you do want to see the per-posting running totals. So we should ask ourselves, is it sufficiently useful to justify further complicating the CLI ? What UI (flag) would you propose ?

I think a big advantage of this solution is that you get much more information but still have a good overview. In particular I miss the the comments (A, B, B in this example) and account names. Just ... is not very informative.

Which flag would I propose? Let me think! I was thinking of --total or -T, like for the balance command. One could also think that this option would not reduce the second column but add a third column with the total result of each transaction. One could even have this as the default always, like

2021-01-01   account                                40 €          40 €
             bccount                              -120 €         -80 €
             cccount                                60 €         -20 €          -20 €
2021-02-01   account                               -50 €         -70 €
             bccount                               600 €         530 €
             cccount                              -560 €         -30 €          -30 €
2021-03-01   account                                70 €          40 €
             bccount                               -30 €          10 €
             cccount                                10 €          20 €           20 €

LaurenzWiskott2 avatar Dec 07 '21 21:12 LaurenzWiskott2

... or printing it boldface would already be quite some help, I think.

2021-01-01 account 40 € 40 € bccount -120 € -80 € cccount 60 € -20 € 2021-02-01 account -50 € -70 € bccount 600 € 530 € cccount -560 € -30 € 2021-03-01 account 70 € 40 € bccount -30 € 10 € cccount 10 € 20 €

2021-01-01   account                                40 €          40 €
             bccount                              -120 €         -80 €
             cccount                                60 €         **-20 €**
2021-02-01   account                               -50 €         -70 €
             bccount                               600 €         530 €
             cccount                              -560 €         **-30 €**
2021-03-01   account                                70 €          40 €
             bccount                               -30 €          10 €
             cccount                                10 €          **20 €**

Well, that doesn't display well here either way, but you know what I mean, I guess.

LaurenzWiskott2 avatar Dec 07 '21 21:12 LaurenzWiskott2

... and/or having an option to just print the last line of each transaction. That would give a nice compact overview.

(I know that areg shows just one line per transaction, but it does not allow to process several accounts as a group.)

LaurenzWiskott2 avatar Dec 09 '21 16:12 LaurenzWiskott2