Alternative --empty option that also shows accounts with no postings

4 views
Skip to first unread message

Henning Thielemann

unread,
Jul 22, 2026, 7:34:08 AM (2 days ago) Jul 22
to hle...@googlegroups.com

$ cat hledger-journal-empty

2026-07-22 income
assets:bank:checking 1 Euro
income:salary

$ hledger -f hledger-journal-empty balance --empty --period 2026
1 Euro assets:bank:checking
-1 Euro income:salary
--------------------
0

$ hledger -f hledger-journal-empty balance --empty --period 2025
--------------------
0

From the documentation and the test cases it seems that this behavior is
intended.

However, I'd prefer to get:

$ hledger -f hledger-journal-empty balance --empty --period 2025
0 Euro assets:bank:checking
0 Euro income:salary
--------------------
0


I want to get a number for every account that is defined using the
"account" directive or that has any posting at any time stamp. I need
this, because I want to export that balance to ODS and then lookup numbers
in LibreOffice Calc using the VLOOKUP function.

Do we need another --empty option or can I get my wanted answer in another
way?

Simon Michael

unread,
Jul 22, 2026, 7:59:39 AM (2 days ago) Jul 22
to hle...@googlegroups.com
That's a good question. I couldn't find a way either. Except to add
some dummy entries, which must be dated within the report period:

2025-01-01
assets:bank:checking 0

2025-01-01
income:salary 0

I guess it suppresses accounts with no activity during the report
period, even if account declarations exist for them, to avoid cluttering
reports with ancient accounts that you don't want to see. This is
something account lifetimes could help with
(https://github.com/simonmichael/hledger/issues/1389).

Henning Thielemann

unread,
Jul 22, 2026, 10:55:03 AM (2 days ago) Jul 22
to hle...@googlegroups.com

On Wed, 22 Jul 2026, Simon Michael wrote:

> I guess it suppresses accounts with no activity during the report
> period, even if account declarations exist for them, to avoid cluttering
> reports with ancient accounts that you don't want to see. This is
> something account lifetimes could help with
> (https://github.com/simonmichael/hledger/issues/1389).

I like the idea of account lifetimes. I also have some accounts in my
journals that already terminated.

However, in order to solve my problem above I would not add an account
lifetime to the idle account but the --empty option must show the zero
value though. That is, the current output of "balance --empty" would
change which might surprise other users.

Simon Michael

unread,
Jul 22, 2026, 11:40:29 AM (2 days ago) Jul 22
to hle...@googlegroups.com
Henning Thielemann
<google...@henning-thielemann.de> writes:

> However, in order to solve my problem above I would not add an account
> lifetime to the idle account but the --empty option must show the zero
> value though. That is, the current output of "balance --empty" would
> change which might surprise other users.


I didn't quite understand this yet, but I'm imagining something like

account assets:bank:checking ; open:2020-01-01
account assets:bank:savings ; open:2020-01-01, close:2023-12-31
account income:salary ; open:2000-01-01
account expenses:food

2026-07-22 income
assets:bank:checking 1 Euro
income:salary

and now `hledger bal -p 2025 -E` would know that both checking and salary
should be shown, even if they have no balance and no activity in 2025,
because they are declared to be open in that period.
savings would not be shown because it's known to be closed,
food would not because it has no explicit lifetime declared (backwards
compatible).

Henning Thielemann

unread,
Jul 22, 2026, 11:53:53 AM (2 days ago) Jul 22
to hle...@googlegroups.com

On Wed, 22 Jul 2026, Simon Michael wrote:

> I didn't quite understand this yet, but I'm imagining something like
>
> account assets:bank:checking ; open:2020-01-01
> account assets:bank:savings ; open:2020-01-01, close:2023-12-31
> account income:salary ; open:2000-01-01
> account expenses:food
>
> 2026-07-22 income
> assets:bank:checking 1 Euro
> income:salary
>
> and now `hledger bal -p 2025 -E` would know that both checking and
> salary should be shown, even if they have no balance and no activity in
> 2025, because they are declared to be open in that period. savings would
> not be shown because it's known to be closed, food would not because it
> has no explicit lifetime declared (backwards compatible).

Indeed, that was the problem I tried to describe.

So, your solution would be to interpret missing account lifetime
declaration as: Lifetime starts at the first transaction and ends at the
last one. Whereas I thought that the most natural interpretation would be
"lifetime is unlimited". But this is not backwards compatible, as you
note.

However, your solution however is not consistent, because the tags 'open'
and 'close' add limits to the lifetime, thus missing tags should mean "no
limits". Maybe it would be a compromise to also have a directive that
makes "unlimited" the default for all accounts? Or a directive that
enables to add lifetime tags and forbids them otherwise?

Simon Michael

unread,
Jul 22, 2026, 12:59:25 PM (2 days ago) Jul 22
to hle...@googlegroups.com
Perhaps logically it seems inconsistent, but would that do any harm ?

It seems pragmatic not to change the established behaviour of many
reports. Though there'd be no harm in experimenting and estimating the
real impact.

Effectively, there'd be four states: undeclared, declared, open, closed.

I'd be wary of adding more directives/options than necessary..

A different idea, not tied to account lifetimes: add an -a/--all flag to all
balance reports (print also has one of these). For balance reports,
it would be a stronger form of -E/--empty (as you were suggesting).
So we might have:

default : show accounts active in the period & with non-zero balance
-E : show accounts active in the period
-a : show all accounts (new)

and when account lifetimes come, maybe:

-a : show all accounts open in the period

Henning Thielemann

unread,
Jul 22, 2026, 1:13:39 PM (2 days ago) Jul 22
to hle...@googlegroups.com

On Wed, 22 Jul 2026, Simon Michael wrote:

> Effectively, there'd be four states: undeclared, declared, open, closed.

With declared = open + closed, right?

Simon Michael

unread,
Jul 22, 2026, 1:16:39 PM (2 days ago) Jul 22
to hle...@googlegroups.com
Simon Michael <si...@joyful.com> writes:
> A different idea, not tied to account lifetimes: add an -a/--all flag to all
> balance reports (print also has one of these). For balance reports,
> it would be a stronger form of -E/--empty (as you were suggesting).
> So we might have:
>
> default : show accounts active in the period & with non-zero balance
> -E : show accounts active in the period
> -a : show all accounts (new)
>
> and when account lifetimes come, maybe:
>
> -a : show all accounts open in the period

More precisely:

default : show accounts active and with non-zero balance in the period
-E : show accounts active in the period
-a : show all declared accounts

active = with postings
balance = whatever the report is showing (change, end balance, gain etc)
declared = declared by an account directive anywhere
open = declared to be open

And when account lifetimes come, maybe we'd change -a's meaning to:

-a : show all accounts open during any part of the period

(This last would give up the ability to show all declared accounts,
again. Would we wish for another stronger flag then, like --declared ?
I think if you have explicitly declared an account's lifetime,
you really never want to see it in reports before or after that lifetime.

Henning Thielemann

unread,
Jul 22, 2026, 1:20:24 PM (2 days ago) Jul 22
to hle...@googlegroups.com

On Wed, 22 Jul 2026, Simon Michael wrote:

> And when account lifetimes come, maybe we'd change -a's meaning to:
>
> -a : show all accounts open during any part of the period
>
> (This last would give up the ability to show all declared accounts,
> again. Would we wish for another stronger flag then, like --declared ? I
> think if you have explicitly declared an account's lifetime, you really
> never want to see it in reports before or after that lifetime.

This might end up in the same situation as -Wall in GHC: It just does not
mean "all" anymore but people continue to expect it that way.

Simon Michael

unread,
Jul 22, 2026, 1:22:28 PM (2 days ago) Jul 22
to hle...@googlegroups.com
Henning Thielemann
<google...@henning-thielemann.de> writes:

>> Effectively, there'd be four states: undeclared, declared, open, closed.
>
> With declared = open + closed, right?

No, by declared I meant declared accounts with unknown lifetime (what we
currently have).

And by open/closed I mean subsets of the declared accounts, the ones
with a known lifetime (or at least half known, ie with just an open
date).

open/closed state is always relative to some date of course; when we
don't have a reference date, we could only say the account is declared
or not.

Simon Michael

unread,
Jul 22, 2026, 1:25:08 PM (2 days ago) Jul 22
to hle...@googlegroups.com
Henning Thielemann
<google...@henning-thielemann.de> writes:

> This might end up in the same situation as -Wall in GHC: It just does
> not mean "all" anymore but people continue to expect it that way.

True..

Henning Thielemann

unread,
Jul 23, 2026, 7:26:29 PM (24 hours ago) Jul 23
to hle...@googlegroups.com

On Wed, 22 Jul 2026, Simon Michael wrote:

> Henning Thielemann <google...@henning-thielemann.de> writes:
>
>>> Effectively, there'd be four states: undeclared, declared, open, closed.
>>
>> With declared = open + closed, right?
>
> No, by declared I meant declared accounts with unknown lifetime (what we
> currently have).

I see that "balance" already has a "--declared" option. This almost fits
my needs, but I need that it shows parent accounts of declared but empty
accounts. I think I should make "--no-elide" let them appear.

Simon Michael

unread,
10:56 AM (8 hours ago) 10:56 AM
to hle...@googlegroups.com
Henning Thielemann
<google...@henning-thielemann.de> writes:

> I see that "balance" already has a "--declared" option. This almost
> fits my needs, but I need that it shows parent accounts of declared
> but empty accounts. I think I should make "--no-elide" let them
> appear.

I had forgotten that. It does sound like exactly what's wanted:

Showing declared accounts

With --declared, accounts which have been declared with an account
directive will be included in the balance report, even if they have no
transactions. (Since they will have a zero balance, you will also need
-E/--empty to see them.)

More precisely, leaf declared accounts (with no subaccounts) will be
included, since those are usually the more useful in reports.

The idea of this is to be able to see a useful "complete" balance
report, even when you don't have transactions in all of your declared
accounts yet.

..except there can still be undeclared parents that aren't displayed ?

Yes that sounds good, --no-elide as the right kind of meaning. So you'd
get your full table of account balances with:
bal -E --declared --no-elide ?

Later if we have account lifetimes, this becomes slightly more complicated.
We might instead write:
bal -E --open --no-elide ?


Reply all
Reply to author
Forward
0 new messages