Hledger: csv rules: an amount set to 0 is not displayed, and considered missing

Created on 10 Nov 2019  路  11Comments  路  Source: simonmichael/hledger

Post #1095: I wanted to generate some placeholder postings, with zero amounts. But if you assign 0 to an amount (with or without a currency symbol), the amount is not shown in the generated transaction, and if you have more than one of these it complains "can't have more than one real posting with no amount". Instead, an explicit zero amount should be shown.

A BUG csv

Most helpful comment

Another unfortunate side effect of this bug is that we cannot generate transactions that are strictly for the purpose of balance assertion without affecting any account balances. Ledger csv import will insist upon generating the following transaction if given a zero amount and non-zero balance amount (this may generate a unbalanced transaction because it implicitly changes the account balance if the account balance is not equal to the balance number):

2019/12/03 * Balance assertion
    Assets:Example            = $1234.56

Which has a completely different meaning than this transaction (this affects the account balance by zero and additionally does a balance assertion):

2019/12/03 * Balance assertion
    Assets:Example            0 = $1234.56

For my CSV imports, it doesn't make sense to attach my balance assertions to the last transaction in the CSV import because my balance assertion happens on a date completely on its own where there might not be any actual transactions (such as a statement date or the date a data file was downloaded from a financial institution website). It would make more sense to have the ability for the CSV import to actually generate a zero amount transaction with a balance assertion attached to it.

All 11 comments

Time for judgement call: if zero is a sensible amount, then #570 is back (and use-case in #570 seems more real-lifeish to me, to be honest).

Brainstorming:

  • there could be a way to nuke zero amounts in field assignment (messy)
  • there could be top-level statement governing whether zeros are preserved
  • or always keep zeroes and we go back to #570 being a bug

Honestly, last outcome seems like a dead-end to me: in scenarios where csv file contains "fees", "commission", etc which one tries to put into separate posting, you could imagine seeing zeroes a lot, and always keeping them seems like a recipy for a very noisy conversion, unnecessarily so.

I guess I don't understand how #570 causes the current behaviour. I'm pretty sure we should allow generation of postings with an explicit zero amount though - I need it myself and it's a natural thing to expect to work.

Relationship to #570 is this: easiest and cleanest way to fix #570 was to just ignore zero values in amount fields. Anything less generic will require complicated code and complicated docs to explain it.
For example, if amount-in=0 and amount-out=5 is fine, then surely amount=0 + amount-in=0 + amount-out=5 should also be fine, right? But then, it seems, it would be weird to ignore zero amounts in some contexts, but keep them in others, according to some opaque rules.

Another unfortunate side effect of this bug is that we cannot generate transactions that are strictly for the purpose of balance assertion without affecting any account balances. Ledger csv import will insist upon generating the following transaction if given a zero amount and non-zero balance amount (this may generate a unbalanced transaction because it implicitly changes the account balance if the account balance is not equal to the balance number):

2019/12/03 * Balance assertion
    Assets:Example            = $1234.56

Which has a completely different meaning than this transaction (this affects the account balance by zero and additionally does a balance assertion):

2019/12/03 * Balance assertion
    Assets:Example            0 = $1234.56

For my CSV imports, it doesn't make sense to attach my balance assertions to the last transaction in the CSV import because my balance assertion happens on a date completely on its own where there might not be any actual transactions (such as a statement date or the date a data file was downloaded from a financial institution website). It would make more sense to have the ability for the CSV import to actually generate a zero amount transaction with a balance assertion attached to it.

just to add more real world examples of where one might see this, this is how my credit union handles interest charges every month:

"Date","Description","Comments","Check Number","Amount","Balance","Category","Note"
"10/01/2019"," PAYMENT","","","-$96.00","","",""
"10/05/2019"," NETFLIX","","","$30.01","","",""
"10/06/2019"," SPECTRUM","","","$65.99","","",""
"10/29/2019","Interest Charge on Cash Advances","","","$0.00","","",""
"10/29/2019","Interest Charge on Purchases ","","","$0.00","","",""

I believe the rework for #1226, in master, also solved this:

# csv rules
date 2020-01-01
amount1 0
amount2 0
amount3 0
amount4 0
amount5 0
$ hledger-1.17.1 print
2020-01-01



md5-ea301ab41372b7571a34dbf57a6fa2cb



$ hledger-1.17.99 print
2020-01-01
    expenses:unknown               0
    expenses:unknown               0
    expenses:unknown               0
    expenses:unknown               0
    expenses:unknown               0

Another unfortunate side effect of this bug is that we cannot generate transactions that are strictly for the purpose of balance assertion without affecting any account balances.

I am in the same boat here. Another related issue is that I cannot seem to get the 0 that is generated here to have a currency symbol. So it's generating:

2020-09-18 Total balance
    assets:splitwise:ashfield               0 = $467.36

and I would like it to either remove the amount completely or at least make it $0.

If it doesn't have a currency, then the hledger UI shows it incorrectly:

Screen Shot 2020-09-19 at 7 54 48 AM

@saulshanabrook could you provide a reproducible example of your issue ? As far as I know, the original issue here was fixed by 1.18:

2020-01-01,
fields date,
account1 assets:checking
amount1  $0
balance1 $0



md5-ea301ab41372b7571a34dbf57a6fa2cb



$ hledger-1.18 -f a.csv print
2020-01-01
    assets:checking               0 = $0

If it's just that the 0's are lacking a commodity symbol, that's always true in hledger (zero is a commodityless amount).. except I think there is some special handling in hledger-web exactly to make that chart work better. Feel free to open a separate issue for that.

PS I guess you did provide the example, and I think I understand it now. I'll move that to a new issue unless you beat me to it.

@simonmichael Thank you so much for opening a new issue for this! That's spot on.

I appreciate your work on this package as well!

Was this page helpful?
0 / 5 - 0 ratings