Filter by acount and related account

30 views
Skip to first unread message

Savo Lazic

unread,
Dec 28, 2020, 11:16:40 PM12/28/20
to Ledger
Here is an example ledger:

2015-03-16      NETFLIX.COM
    Expenses:Entertainment:Streaming
    Liabilities:Credit Card:VISA   $-7.99
2015-04-16      NETFLIX.COM
    Expenses:Entertainment:Streaming
    Liabilities:Credit Card:Mastercard   $-7.99

I know how to individually filter for Streaming and VISA. I am not able to figure out how to pull out all the records of Netflix being payed for by VISA only using the account (Streaming) and related account (VISA) identifiers. I do not want to use payee as that changes over time.

I tried using the -r and --limit option, but it did not work.

Thanks.

john nduli

unread,
Dec 29, 2020, 7:46:12 AM12/29/20
to ledge...@googlegroups.com
You could try to use regexes for this. Something like this:

ledger reg "expr" "payee =~/.*netflix.*/" and "expr" "account =~
/.*Streaming/"
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Ledger" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ledger-cli/c85e0003-c359-4cbc-9c88-b0c766e5c3e7n%40googlegroups.com.



--
Regards,
jnduli

Martin Michlmayr

unread,
Dec 29, 2020, 8:09:33 AM12/29/20
to ledge...@googlegroups.com
* Savo Lazic <lazi...@gmail.com> [2020-12-28 18:48]:
> I know how to individually filter for Streaming and VISA. I am not
> able to figure out how to pull out all the records of Netflix being
> payed for by VISA only using the account (Streaming) and related
> account (VISA) identifiers. I do not want to use payee as that
> changes over time.

reg Expenses:Entertainment:Streaming -l "any(account =~ /Liabilities:Credit Card:VISA/)"

> I tried using the -r and --limit option, but it did not work.

No, you need: any(account =~ /.../)

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

Martin Michlmayr

unread,
Dec 29, 2020, 8:25:41 AM12/29/20
to ledge...@googlegroups.com
* Martin Michlmayr <t...@cyrius.com> [2020-12-29 21:09]:
> reg Expenses:Entertainment:Streaming -l "any(account =~ /Liabilities:Credit Card:VISA/)"
>
> > I tried using the -r and --limit option, but it did not work.
>
> No, you need: any(account =~ /.../)

Just to make this clearer. Let's say you have a transaction with two
postings, accounts A and B.

reg A --related/-r *shows* the other account (B), but the query is on A

with any(), you query on A (reg A), but you can additionally require
that at least one account in the transaction involves B.

Savo

unread,
Dec 29, 2020, 9:36:51 AM12/29/20
to Ledger
The any() command did it. Thanks.
Reply all
Reply to author
Forward
0 new messages