Hledger import overzealous

Hi All,

Happy new year!

Hoping to get some help / insights.

I have a csv file with an example entry like this (irrelevant fields omited):

`..Transaction Date, Narration,...,Category`
12/01/2026,..,HardwareHouse BAYSWATER,... ,Home Maintenance

There is a rule file containing the accompanying rule to appropriately appoint the Home Maintenance to appropriate accounts:

skip 1

fields , ,date,description, ,amount-in,amount-out, , ,Category

date-format %-d/%-m/%Y

if Home Maintenance
	account1 Expenses:Home:Maintenance 
	account2 Assets:myBank:mainaccount:Home:Maintenance

However hledger import gives the following transaction block:

2026-01-12 HardwareHouse BAYSWATER AUS
    Expenses:Home:Water                             $12.45
    Assets:Bankwest:transaccount:Home:Water       $-12.45

Which does not line up with the rules file. There seems to be something going on with import, where perhaps this was miscategorised before and now it's stuck with this rule and it overrides the rules csv.

Is there a way to reset the importer or something that I can do here.

Advice sincerely appreciated.

Heppy new year @D-K

You haven't shown the exact output, but perhaps you're seeing an entry previously imported using an older version of the rules ?

Test your current csv rules without importing: hledger -f foo.csv print

Check the current import state for foo.csv: cat .latest.foo.csv

Reset the import state so that all records are considered new: rm .latest.foo.csv

Update the import state so that all records are considered old: hledger import foo.csv --catchup

Set the import state back just a bit to redo an import: save the appropriate date(s) in .latest.foo.csv and run hledger import foo.csv [--dry-run] again.

Appreciate the quick response, thank you.

And thanks for the hints and tips, will have a deeper dive tonight and see where the error is.

thanks again

1 Like

I realise the mistake was mine entirely.

After reading through the Hledger documentation. My rule file contained things like this:

skip 1

fields , ,date,description, ,amount-in,amount-out, , ,Category

date-format %-d/%-m/%Y

if Home Maintenance
	account1 Expenses:Home:Maintenance 
	account2 Assets:myBank:mainaccount:Home:Maintenance

However I wasn't specifying which column should the rule needs to apply to. I would like the rule to be derived from the Category Column. But I assume because I wasn't specifying it properly Hledger impor was taking it from perhaps a combination of "description" as well as "Category". However, after fixing it:

skip 1

fields , ,date,description, ,amount-in,amount-out, , ,Category

date-format %-d/%-m/%Y

if %10 Home Maintenance
	account1 Expenses:Home:Maintenance 
	account2 Assets:myBank:mainaccount:Home:Maintenance

No problems in import.

I will also take this opportunity to extend a huge thank you to Simon for the creation of Hledger, what wonderful software. Thanks.

1 Like