How to extract data when using ledger-cli

Hi all..

I've got some definitions similar to the following that I'm trying to both reporting of and also to be able to search said items. This is my example care of some help the other day from Simon (with some tailoring to my example environment):

account Income:Main Org:Donations:John Doe
  ; cust-id: John Doe
  ; address: 132 first street
  ; city:    Lincoln
  ; state:   NE
  ; Zip:     92010
  ; email:   bar@foo.com
  ; phone:   123-456-7890

alias john-doe = Income:Main Org:Donations:John Doe

I'm hoping to be able to get this to work with ledger and while Simon was able to do what I wanted in hledger I can't get it to work in ledger-cli (which I'm stuck with for the moment). The command in hledger that doesn't work in ledger is :

% hledger -f main.journal bal revenues --tree --no-elide --yearly --invert --pivot state:city:cust-id

When I do the closest as I can in ledger I get the following output:

% ledger -f ./books.ledger bal Income --yearly --invert --pivot state:city:cust-id
         $100,020.00  Income:Main Org:Donations
              $10.00    John Doe
              $10.00    Ken Smith
--------------------
         $100,020.00

I do not see a --tree available for ledger .. I really just want a way to dump a report of all these customer names & their associate info if desired AND a way to query an address from the bunch (e.g. look for customers living in Seattle)..

I hope this makes sense.. I went looking at all the command line args for ledger and either I'm missing something and it's right under my nose or ??

Hi @ps23Rick, I'm not a regular ledger user but just a few pointers:

  • Search both the manual on the website and the output of ledger --help
  • ledger bal shows the hierarchy by default, no need for --tree, which is a hledger flag
  • --yearly doesn't affect ledger bal, you'll get a single column
  • I'm not sure you can combine multiple fields in a pivot with ledger, try one at a time
ledger accounts

See Ledger's account documentation. There's no "associate info" the way you've described it in your books.ledger; at least none you can pivot on. Transactions, have tags we can pivot on; not Accounts.

My workaround for this creates a journal like so

account Income:Main Org:Donations:John Doe
account Income:Main Org:Donations:Jack Black
account Income:Main Org:Donations:James Fame
account Income:Main Org:Donations:Chris Risk

= /Chris Risk$/
  ; cust-id: Chris Risk
  ; address: 132 first street
  ; city:    Baltimore
  ; state:   MD
  ; Zip:     92040
  ; email:   bin@foo.com
  ; phone:   123-456-7893

= /John Doe$/
  ; cust-id: John Doe
  ; address: 132 first street
  ; city:    Lincoln
  ; state:   NE
  ; Zip:     92010
  ; email:   bar@foo.com
  ; phone:   123-456-7890

= /Jack Black$/
  ; cust-id: Jack Black
  ; address: 132 first street
  ; city:    Lincoln
  ; state:   NE
  ; Zip:     92020
  ; email:   baz@foo.com
  ; phone:   123-456-7891

= /James Fame$/
  ; cust-id: James Fame
  ; address: 132 first street
  ; city:    Hollywood
  ; state:   LA
  ; Zip:     92030
  ; email:   qux@foo.com
  ; phone:   123-456-7892

2024-09-23 donation
    Income:Main Org:Donations:Chris Risk
    assets:checking      $10

2024-09-23 donation
  Income:Main Org:Donations:John Doe
  assets:checking      $20

2024-09-23 donation
  Income:Main Org:Donations:James Fame
  assets:checking      $30

2024-09-23 donation
  Income:Main Org:Donations:Jack Black
  assets:checking      $40

The differences are

  • no need for the aliases. Just like @simonmic said… it's just another set of names to remember. You could keep them for convenience if you wish.
  • I used automated transactions to add the account information. Yours could be more targeted. This way, every transaction has the account details we want. Verify this with ledger print

Now we can answer…

…with our original pivot idea…

$ ledger bal --pivot state --invert

                $-100  assets:checking
                 $100  state
                  $30    LA:Income:Main Org:Donations:James Fame
                  $10    MD:Income:Main Org:Donations:Chris Risk
                  $60    NE:Income:Main Org:Donations
                  $40      Jack Black
                  $20      John Doe
 --------------------
                    0

Hope this helps, at least put you on the right path to solving this.

Ah good point, attaching tags to accounts must be another hledgerism.