Unexpected behavior using 'expr:'

10 views
Skip to first unread message

Johan van Litsenborgh

unread,
Feb 26, 2024, 12:38:55 PMFeb 26
to hledger
Good day

I have been testing using 'expr:' for more complex queries and recreated a scenario that hopefully explains what I am trying to achieve and what I am getting instead.

Journal File

2023-10-09 Rental Deposit
assets:day_to_day_accounts:bank
expenses:housing:rent 400

2023-10-09 Rental Agreement Admin Fee
assets:day_to_day_accounts:bank -30
expenses:housing:rent

2023-11-26
assets:day_to_day_accounts:bank -200
expenses:housing:rent

2023-12-26
assets:day_to_day_accounts:bank -200
expenses:housing:rent

2023-12-27 Food
assets:day_to_day_accounts:bank
expenses:day_to_day 25

2024-01-09 Food
assets:day_to_day_accounts:bank
expenses:day_to_day 25

2024-01-26
assets:day_to_day_accounts:bank -200
expenses:housing:rent

2024-02-18
assets:day_to_day_accounts:bank -15
expenses:financial:tax

Then I have two queries that both work as intended that I want to combine, which doesn't work on the combine, as follows:

Query 1

The rent paid prior to this year, excluding the 'Rental Deposit'.

hledger -f finances.hledger is expr:"expenses:housing:rent AND 'not:desc:Rental Deposit' AND date:..2024-01-01"

Screenshot 2024-02-26 123532.png

Query 2

All expenses for the current year, excluding tax.

hledger -f finances.hledger is expr:"^expenses: AND not:expenses:financial:tax AND date:2024-01-01..tomorrow"

Screenshot 2024-02-26 123840.png

Combining the two expressions to achieve a single IS View

hledger -f finances.hledger is expr:"( expenses:housing:rent AND 'not:desc:Rental Deposit' AND date:..2024-01-01 ) OR ( ^expenses: AND not:expenses:financial:tax AND date:2024-01-01..tomorrow )"

Screenshot 2024-02-26 123959.png

But this only returns the data from the second query, disregarding the first part before the OR.

Any idea as to why I am seeing this behavior?

Simon Michael

unread,
Feb 26, 2024, 3:13:46 PMFeb 26
to hle...@googlegroups.com
Are you sure it's not working ? When I run `print` instead, the results look ok.
--
You received this message because you are subscribed to the Google Groups "hledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hledger+u...@googlegroups.com.




Johan van Litsenborgh

unread,
Feb 26, 2024, 3:21:40 PMFeb 26
to hledger
You're right print returns all the transactions expected, but `hledger is` which I ran returns a different sum than expected.

Should I be using print?

Johan van Litsenborgh

unread,
Feb 26, 2024, 3:32:42 PMFeb 26
to hledger
I got it working by piping a print with the same expression into an 'hledger is' as follows:

hledger -f finances.hledger print expr:"( expenses:housing:rent AND 'not:desc:Rental Deposit' AND date:..2024-01-01 ) OR ( ^expenses: AND not:expenses:financial:tax AND date:2024-01-01..tomorrow )" | hledger -f- is

But I am finding it a bit weird that the expression is interpreted differently for different commands.

Simon Michael

unread,
Feb 26, 2024, 3:54:29 PMFeb 26
to hle...@googlegroups.com
I see what you mean!

One thing is that print matches transactions, unlike most other reports which match individual postings. I don't think that explains this case though. I can reproduce it more clearly with register:

$ hledger reg expr:"( expenses:housing:rent AND 'not:desc:Rental Deposit' AND date:..2024-01-01 )"
2023-10-09 Rental Agreement ..  ex:housing:rent                 30            30
2023-11-26                      ex:housing:rent                200           230
2023-12-26                      ex:housing:rent                200           430

$ hledger reg expr:"( ^expenses: AND not:expenses:financial:tax AND date:2024-01-01..tomorrow )"
2024-01-09 Food                 expenses:day_to_day             25            25
2024-01-26                      ex:housing:rent                200           225

OR-ing the two queries above, it sure seems like we should be seeing all five postings:

$ hledger reg expr:"( expenses:housing:rent AND 'not:desc:Rental Deposit' AND date:..2024-01-01 ) OR ( ^expenses: AND not:expenses:financial:tax AND date:2024-01-01..tomorrow )"
2024-01-09 Food                 expenses:day_to_day             25            25
2024-01-26                      ex:housing:rent                200           225

We should open a bug report I think.

Johan van Litsenborgh

unread,
Feb 27, 2024, 7:50:07 AMFeb 27
to hledger
Logged a bug on github for this issue:

Reply all
Reply to author
Forward
0 new messages