hledger icon indicating copy to clipboard operation
hledger copied to clipboard

with reg -H, should amt: filter postings before the start date ?

Open simonmichael opened this issue 2 years ago • 1 comments

As discussed in chat, amt: currently filters postings both before and after the start date:

2022-01-01
    (a)         5

2022-01-02
    (a)        -1

# 1. Both transactions are within the report period, but only the second is matched
# by amt: and contributes to the running total:
$ hledger -f- reg -w60 amt:'<0'
2022-01-02            (a)                   -1            -1

# 2. Only the second transaction is within the report period. The -H flag normally  
# would add the 5 balance from before the -b start date to the running total,
# but the amt: query excludes it.
$ hledger -f- reg -w60 amt:'<0' -H -b 2022-01-02
2022-01-02            (a)                   -1            -1

Should it instead filter only postings after the start date ?:

# 2. Only the second transaction is within the report period. The -H flag adds the 5
# balance from before the -b start date to the running total, unfiltered by amt:.
# Only the postings to be displayed (ie, within  the report period) are filtered by amt:.
$ hledger -f- reg -w60 amt:'<0' -H -b 2022-01-02
2022-01-02            (a)                   -1             4

Which behaviour would be more intuitive / more useful ?

Note, even if we ensure the starting balance is accurate, the running balance will still not be entirely accurate since the query will exclude some of the displayed items; with -H it is actually "starting historical balance + running total of displayed items". If you changed it to "accurate historical balance on the date of each displayed item", the right column will show actual historical balances, but with discontinuities where unmatched items are excluded. I have assumed this third behaviour would be too confusing.

simonmichael avatar Apr 07 '22 09:04 simonmichael

Just as a note here, as the main concern behind this issue was why hledger -f- reg 'amt:<0' would not return running balances.

I believe that the source of the issue didn't have to do with the use or -H flag or -b at all, but rather, the following test case:

# 1. When running `reg` command without an `amt` query, the results display the running balance
$ hledger -f- reg -w80
2022-01-01                      (a)                              5            5
2022-01-02                      (a)                             -1            4

# 2. When running `reg` command WITH an `amt` query, the results STILL display the running balance
$ hledger -f- reg -w80 amt:'<0' 
2022-01-02                      (a)                             -1            4

for the moment, the current behaviour of (2) is removing the running balance 4 and only displaying the running total -1

$ hledger -f- reg -w80 amt:'<0' 
2022-01-02                      (a)                             -1            -1

zanona avatar Apr 07 '22 10:04 zanona