Filter transactions based on auxdate but display normal date

47 views
Skip to first unread message

Shredder

unread,
Dec 29, 2020, 12:43:37 PM12/29/20
to Ledger
Hello everyone,

I would like to filter transactions based on the auxdate (effective date), i.e. use something equivalent to -b [Date] and -e [Date], but for the auxdate. I am not using the --aux-date/--effective option because I would still like to display the normal date in the report output. Do you have any ideas what would be the best way to achieve this?

(Due to other reasons I would want to avoid switching the normal date and auxdate, even if this would be an easy solution for this problem alone.)

Thanks a lot!
Shredder

Martin Michlmayr

unread,
Dec 29, 2020, 10:34:58 PM12/29/20
to ledge...@googlegroups.com
* Shredder <d3rsh...@gmail.com> [2020-12-29 09:43]:
> I would like to filter transactions based on the auxdate (effective
> date), i.e. use something equivalent to -b [Date] and -e [Date], but
> for the auxdate. I am not using the --aux-date/--effective option
> because I would still like to display the normal date in the report
> output. Do you have any ideas what would be the best way to achieve
> this?

ledger -f d reg -l "aux_date >= [2020-10-02]"

--
Martin Michlmayr
https://www.cyrius.com/

Shredder

unread,
Dec 30, 2020, 1:02:15 PM12/30/20
to Ledger
Hello Martin,

amazing, this works like a charm. Thanks for your quick reactions, they help me a lot :)

Shredder

Shredder

unread,
Dec 30, 2020, 1:23:46 PM12/30/20
to Ledger

Hey again Martin and everyone,

I'm still getting problems as not all of my transactions contain aux_dates, which results in this error:

While comparing if  is less than 2020/12/22:
While handling posting from streamed input:
Error: Cannot compare an uninitialized value to a date

Any ideas how this can easily be resolved?

Thanks,
Shredder

Shredder

unread,
Dec 30, 2020, 1:47:10 PM12/30/20
to Ledger
I would actually want to use the date instead of the aux_date whenever the aux_date is missing.
I found a (quite ugly) workaround that achieves this: Instead of using

-l "aux_date > [2020/12/19] and aux_date < [2020/12/22]"

it seems to work to use

-l "(to_string(aux_date) > to_string([2020/12/19]) and to_string(aux_date) < to_string([2020/12/22])) or (to_string(aux_date) == '' and date > [2020/12/19] and date < [2020/12/22])

which is quite ugly, but as I am abstracting via scripts anyway, this should be fine for now. If anyone has a more elegant solution, please let me know :)

Thanks,
Shredder

Martin Michlmayr

unread,
Dec 30, 2020, 9:37:41 PM12/30/20
to ledge...@googlegroups.com
* Shredder <d3rsh...@gmail.com> [2020-12-30 10:23]:
> I'm still getting problems as not all of my transactions contain aux_dates,
> which results in this error:
>
> While comparing if is less than 2020/12/22:

Oh yes, interesting.

This seems to work:

ledger -f d reg -l "(aux_date or date) >= [2020-10-11]"
Reply all
Reply to author
Forward
0 new messages