In queries: Match a date on a certain account
First I like to wish clarification what date in a query actually matches on.
Every posting in a transaction can have a different date. What date does a date query actually match?
I assume that if any posting's date falls into a queried period then the transaction is selected.
If this is true, this is problematic since it means that in a multi-period balance some transactions are included in multiple periods.
For now, I observed the problem in hledger-web since a date query combined with inacct shows transactions with inacct-posting dates that do not match the date period. I think I need a date query that only matches the date of certain accounts.
I guess the solution in my case is to better not use posting dates, at all. At least, the meaning of date queries with respect to posting dates should be clarified in the query docs.
It depends on the type of report. Generally
-
print,aregister, hledger-web's /journal view, hledger-web's /register view, hledger-ui's register screen are transaction-based, and transaction dates are matched. -
registerand all the balance reports are posting-based, and posting dates are matched.
I feel there was some special doc or code notes about this sort of thing - complications of multiple dates at report boundaries - but I haven't found it.
Basically if you need to see a report that filters by posting date, hledger-web's register isn't the right tool; you need hledger register for that.
hledger-web's balance report (in the sidebar) should be respecting your posting dates and date: query though. So I'd expect you could see those balances disagreeing with what the register shows, in such cases.
On Thu, 17 Jul 2025, Simon Michael wrote:
It depends on the type of report. Generally
print, aregister, hledger-web's /journal view, hledger-web's /register view, hledger-ui's register screen are transaction-based, and transaction dates are matched.
If hledger-web's date query would match the transaction date, everything would be fine. But it seems to match both transaction and posting date, or multiple posting dates, I don't know.
hledger-web's balance report (in the sidebar) should be respecting your posting dates and date: query though. So I'd expect you could see those balances disagreeing with what the register shows, in such cases.
Just checked: You are right, they disagree.
Still confusing.
In Hledger.Reports.AccountTransactionsReport I see this, and a reference to #1731:
-- TODO needs checking, cf #1731
-- | What date should be shown for a transaction in an account register report ?
-- This will be in context of a particular account (the "this account" query)
-- and any additional report query. It could be:
--
-- - if postings are matched by both thisacctq and reportq, the earliest of those
-- matched postings' dates (or their secondary dates if --date2 was used)
--
-- - the transaction date, or its secondary date if --date2 was used.
--
transactionRegisterDate :: WhichDate -> Query -> Query -> Transaction -> Day
transactionRegisterDate wd reportq thisacctq t
| not $ null thisacctps = minimum $ map (postingDateOrDate2 wd) thisacctps
| otherwise = transactionDateOrDate2 wd t
where
reportps = tpostings $ filterTransactionPostings reportq t
thisacctps = filter (matchesPosting thisacctq) reportps
And this: https://hledger.org/hledger.html#aregister-and-posting-dates
aregister shows the earliest of the transaction's date and posting dates that is in-period, and the sum of the in-period postings. In other words it will show a combined line item with just the earliest date, and the running balance will (temporarily, until the transaction's last posting) be inaccurate. Use register -H if you need to see the individual postings.
There is also a --txn-dates flag, which filters strictly by transaction date, ignoring posting dates. This too can cause an inaccurate running balance.
Hi @thielema, coming back to this. Is there an unresolved issue ?