Is it possible to query an account note?

63 views
Skip to first unread message

david whiting

unread,
May 20, 2020, 2:53:40 PM5/20/20
to Ledger
Is it possible to query a note or tag in an account rather than a transaction? For example, if I have an account defined like this:

account Assets:Members:T0001:Fred Smith
        note
1234
       
; ID: 1234


is it possible to produce a register report filtering on ID (or note) instead of account name? I've tried 

ledger.dat reg expr "note =~ /1234/"

and 

ledger.dat reg %ID

and these don't work. Am I trying to do something that is not possible?

Thanks.


David

Charles Hoffman

unread,
May 20, 2020, 4:44:30 PM5/20/20
to Ledger
What I find interesting is that there are a lot of emails on this list about reporting using various "attributes": account, subaccount, period, tags, notes, codes, descriptions, and so forth.  Further, one of the most interesting features of Ledger is the "pivot table" type reporting.

Essentially, journal entries are "dimensional".  All of those "attributes" (account, subaccount, period, tag, code, description, etc.) are in essence dimensions that are used to characterize a transaction so that it can be distinguished effectively from other transactions and work with the transaction information the way you need to.

What if all these "attributes" were implemented consistently as, say, tags.  Seems to me that would make reporting more straight forward and elegant.

Cheers,

Charlie

John Wiegley

unread,
May 20, 2020, 7:01:13 PM5/20/20
to david whiting, Ledger
>>>>> "dw" == david whiting <david.r...@gmail.com> writes:

dw> ledger.dat reg expr "note =~ /1234/"

It would be "tag("ID") =~ /1234/", for your example. Which is also what
'%ID=1234' should mean.

John

david whiting

unread,
May 21, 2020, 2:33:13 AM5/21/20
to Ledger
On Thursday, 21 May 2020 00:01:13 UTC+1, John Wiegley wrote:
>>>>> "dw" == david whiting <david....@gmail.com> writes:

dw> ledger.dat reg expr "note =~ /1234/"

It would be "tag("ID") =~ /1234/", for your example. Which is also what
'%ID=1234' should mean.

John

Thanks. I think there's something I still don't understand. Given the following example.dat:

;; -*- mode: ledger -*-

account
Assets:Members:Fred Smith
       
; ID:1234


account
Assets:Members:Joe Public
       
; ID:5678


2020/05/21 Test
   
Assets:Members:Fred Smith                     20 GBP
   
Income:subs


2020/05/21 Test
   
Assets:Members:Joe Public                     20 GBP
   
Income:subs




When I do:

ledger -f example.dat reg Fred

I get the transaction for Fred. But when I try (with various forms of quoting in case that was the issue):

ledger -f example.dat reg "tag('ID') =~ 1234"
ledger -f example.dat reg 'tag("ID") =~ 1234'
ledger -f example.dat reg "tag("ID") =~ 1234"
ledger -f example.dat reg '%ID =~ 1234'
ledger -f example.dat reg "%ID =~ 1234"


I get no results. 

David

Martin Michlmayr

unread,
May 21, 2020, 2:54:12 AM5/21/20
to ledge...@googlegroups.com
* david whiting <david.r...@gmail.com> [2020-05-20 23:33]:
> I get no results.

I don't think you can query meta-data on account declarations.

John probably thought you were talking about transactions.

See https://github.com/ledger/ledger/issues/1070

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

david whiting

unread,
May 21, 2020, 7:36:24 AM5/21/20
to Ledger
On Thursday, 21 May 2020 07:54:12 UTC+1, Martin Michlmayr wrote:
* david whiting <david....@gmail.com> [2020-05-20 23:33]:
> I get no results.

I don't think you can query meta-data on account declarations.

John probably thought you were talking about transactions.

See https://github.com/ledger/ledger/issues/1070

Thanks. I should have included a complete example in my initial query. I have another approach that will suit my needs and that is to add the ID to the account name, e.g.

account Assets:Members:Fred Smith M1234

(M for member) and then I can just use the normal account query approach. With autocompletion in ledger-mode using accounts named in this way is no more difficult to use than the name alone, and the wonderful flexibility that plain text provides means it will just take a little script to add the IDs to the names. 

I'm still learning, but am really enjoying ledger.

Thanks for your help.

Reply all
Reply to author
Forward
0 new messages