Referring to account in automated transactions

384 views
Skip to first unread message

Justin St-Amant

unread,
Jan 21, 2018, 11:12:49 AM1/21/18
to Ledger
Is there a way to refer to the tail-end of the matched account in an automated transaction, using a variable such as '$account_base' or similar?
The ledger manual has a section that shows how to refer to the matching posting's account, by using '$account', but that expands to the full account name, rather than just the end.

I've been using ledger personally for a year, and now I'd like to implement budgeting. I'm trying to perform budgeting like the "You Need a Budget" system, and I'm trying to setup my account structure like so:

account Assets:Checking
account Assets:Savings
account Assets:Budget:Rent
account Assets:Budget:Food
account Assets:Budget:Utilities
account Expenses:Rent
account Expenses:Food
account Expenses:Utilities

At the start of the month, I want to put money aside for rent (along with all other budgetting categories and savings goals).

2018-02-01 Monthly budget
    [Assets:Budget:Rent]     $600.00
    Assets:Checking        $-2000.00
    Assets:Savings

Now I need an automated transaction that will move the money set aside for rent back to my checking account whenever I spend that money.

2018-02-06 Rent
    Expenses:Rent            $600.00
    Assets:Checking

Should become this after the automated transaction:

2018-02-06 Rent
    Expenses:Rent            $600.00
    Assets:Checking
    [Assets:Budget:Rent]    $-600.00
    Assets:Checking          $600.00

So the automated transaction should look something like this, but using '$account_base' is not valid:

= Expenses
    [Assets:Budget:$account_base]  -1.0
    Assets:Checking                 1.0

Any help with this automated transaction? I've thoroughly searched the manual on how to do this, but it only explicitly tells you that you can use '$account' in the posting's account section. I was thinking that other variables like that might be available, but may be less explicitly documented in the manual.
I also googled this topic, and found little documentation.

Thanks,

-- Justin

cesar...@gmail.com

unread,
Jan 21, 2018, 12:31:15 PM1/21/18
to ledge...@googlegroups.com
hello,

i was looking for something similar. as per this article:

https://frdmtoplay.com/envelope-budgeting-with-ledger/

it seems one needs to create an automated transaction for each type of
budgeted expense.

ie,

= /Expenses:Rent/
    [Assets:Budget:Rent]  -1.0
    Assets:Checking        1.0

your solution would be very powerful indeed.

-cm

Richard Lawrence

unread,
Jan 21, 2018, 1:24:56 PM1/21/18
to cesar...@gmail.com, ledge...@googlegroups.com
cesar...@gmail.com writes:

> Justin St-Amant <jstam...@gmail.com> writes:
>
>> Is there a way to refer to the tail-end of the matched account
>> in an automated transaction, using a variable such as
>> '$account_base' or similar? The ledger manual has a section
>> that shows how to refer to the matching posting's account, by
>> using '$account', but that expands to the full account name,
>> rather than just the end.

> i was looking for something similar. as per this article:
>
> https://frdmtoplay.com/envelope-budgeting-with-ledger/
>
> it seems one needs to create an automated transaction for each
> type of budgeted expense.

I read the same article, and this is one reason that I don't use
very fine-grained "envelopes". Instead, I have just three budget
categories: Fixed (stuff I have no choice about whether or how
much to pay, like rent and utilities), Discretionary (stuff I have
choices about, like groceries or restaurants) and Savings. I find
this system more useful for budgeting than putting every
individual kind of expense in its own account/"envelope".

To implement this system, I use a regexp matching specific Expense
accounts to trigger automatic transactions that should go under
Fixed or Savings. Then, every other transaction in Expenses gets
deducted from the Discretionary budget category. My setup looks
like this:

= expr 'account =~
/expenses:(Rent|Utilities|Medical|Phone|Financial||Taxes)/'
; :FIXED: [assets:Budget:Fixed] -1.0
[assets:Checking] 1.0

= expr 'account =~ /expenses/ and not has_tag("FIXED") and not
(account =~ /Reimbursable/)'
; :DISCRETIONARY: [assets:Budget:Discretionary] -1.0
[assets:Checking] 1.0

= expr 'account =~ /assets:(Retirement|Emergency)/ and
has_tag("contribution")'
; :SAVINGS: [assets:Budget:Savings] (cost * -1.0)
[assets:Checking] (cost * 1.0)

I then use the tags in these automated transactions to produce a
custom balance report for my budget:

$ ledger balance budget -e 'next month'

will show how much is remaining in each assets:Budget account for
the month.

Hope that helps!

--
Best,
Richard

John Wiegley

unread,
Jan 23, 2018, 3:41:27 AM1/23/18
to Justin St-Amant, Ledger
>>>>> "JS" == Justin St-Amant <jstam...@gmail.com> writes:

JS> Is there a way to refer to the tail-end of the matched account in an
JS> automated transaction, using a variable such as '$account_base' or
JS> similar? The ledger manual has a section that shows how to refer to the
JS> matching posting's account, by using '$account', but that expands to the
JS> full account name, rather than just the end.

You can use %(expr) rather than $account, with the ability to refer to the
bound scope (which is the posting that $account is the fullname of), thus, the
following aught to work:

%(account) # same as $account
%(account_base)

John
Reply all
Reply to author
Forward
0 new messages