Related accounts and running totals

120 views
Skip to first unread message

Richard Lawrence

unread,
Feb 14, 2016, 2:25:32 PM2/14/16
to ledger-cli
Hi all,

I have a question about related accounts. I'm on ledger 3.1.0. (I also
use hledger 0.27, which I'd be happy to employ here if it can answer
this question more easily.)

Here is my use case: I keep track of expenses shared with a roommate
under expenses:shared, and at the end of a given reporting period I want
to be able to ask, "How much did I pay to expenses:shared, and how much
did my roommate pay?" to see who owes money to the other.

From the manual, I have gotten this far: I can do

$ ledger --related --display 'account =~ /assets:Me/' reg expenses:shared

to see transactions where I paid toward expenses shared, and similarly I
could use assets:Roommate in the display predicate to see what my
roommate paid.

But as the manual notes, "The running total...is off, however, since a
display expression is being used." The running total reflects all
transactions on expenses:shared, not just the ones that are selected by
the display predicate. So the above command is only useful for telling
me the amounts of the individual transactions displayed; I must tally
them up some other way before I can figure out who owes who, and how
much.

So my question is, is there some way to get a correct running total when
using --related and limiting to a subset of transactions? Perhaps by
using --limit instead of --display, or some kind of fancy format
string...? Nothing I have been able to come up with seems to work.

Thanks for any insights you can provide!

Best,
Richard

John Wiegley

unread,
Feb 15, 2016, 2:08:59 PM2/15/16
to Richard Lawrence, ledger-cli
>>>>> Richard Lawrence <wyl...@gmail.com> writes:

> So my question is, is there some way to get a correct running total when
> using --related and limiting to a subset of transactions? Perhaps by using
> --limit instead of --display, or some kind of fancy format string...?
> Nothing I have been able to come up with seems to work.

The only way to affect the running total is either to use --total or
--display-total to change how it's computed (or displayed), or to use --amount
to change the component values that make it up. --display especially will lead
to mismatched running totals; in fact, its ability to do so is originally why
it was added, so that I could query for data subsets within the context of an
entire report.

--
John Wiegley GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2

Richard Lawrence

unread,
Feb 16, 2016, 12:02:01 PM2/16/16
to John Wiegley, ledger-cli
Hi John and all,

John Wiegley <jo...@newartisans.com> writes:

>>>>>> Richard Lawrence <wyl...@gmail.com> writes:
>
>> So my question is, is there some way to get a correct running total when
>> using --related and limiting to a subset of transactions? Perhaps by using
>> --limit instead of --display, or some kind of fancy format string...?
>> Nothing I have been able to come up with seems to work.
>
> The only way to affect the running total is either to use --total or
> --display-total to change how it's computed (or displayed), or to use --amount
> to change the component values that make it up. --display especially will lead
> to mismatched running totals; in fact, its ability to do so is originally why
> it was added, so that I could query for data subsets within the context of an
> entire report.

Thanks for your reply! Yes, I think that --display is not really what I
want.

I think what I'd like to do is limit transactions by the *related*
account, something like

ledger --limit 'related =~ /assets:Me/' reg expenses:shared

I don't see a way to do this using the available expressions, but I'm
pretty new to this; maybe I've overlooked something?

Best,
Richard
signature.asc

John Wiegley

unread,
Feb 16, 2016, 12:31:27 PM2/16/16
to Richard Lawrence, ledge...@googlegroups.com
>>>>> Richard Lawrence <wyl...@gmail.com> writes:

> I think what I'd like to do is limit transactions by the *related* account,
> something like

> ledger --limit 'related =~ /assets:Me/' reg expenses:shared

One reason this doesn't exist is because there can be multiple related
accounts. I suppose that "related" could become the textual sum of all the
related accounts?

Richard Lawrence

unread,
Feb 16, 2016, 1:55:41 PM2/16/16
to John Wiegley, ledge...@googlegroups.com
John Wiegley <jo...@newartisans.com> writes:

>>>>>> Richard Lawrence <wyl...@gmail.com> writes:
>
>> I think what I'd like to do is limit transactions by the *related* account,
>> something like
>
>> ledger --limit 'related =~ /assets:Me/' reg expenses:shared
>
> One reason this doesn't exist is because there can be multiple related
> accounts.

Right, good point.

> I suppose that "related" could become the textual sum of all the
> related accounts?

After thinking about this, I'm not sure it would work in my current
setup. I have transactions like this:

2015/08/07 Shared credit card payment
liabilities:shared:CC $1000.00
assets:Me:Checking $-600.00
assets:Roommate $-400.00

I'd like to be able to use two different expressions here to generate
two reports, for Me and for Roommate. The first report would include my
$600 payment in the running total of what I've paid toward the shared
account; the second report would include my roommate's $400 payment in
her running total.

So, given my current setup, I guess what I would need is a way to limit
by individual related accounts within a transaction, not just their
textual sum. I was envisioning "related =~ /assets:Me/" in the
pseudo-command above as selecting just my `side' of transactions like
this for inclusion into the report. I have no idea if that's compatible
with the way ledger actually works internally, though.

(This may not be the best way to record such payments, though it does
make it easy to see at a glance that the correct total amount was paid,
while recording the different contributions. But I'm willing to switch
to separate transactions if it makes the reporting easier.)

Best,
Richard
signature.asc

Manuel Amador (Rudd-O)

unread,
Feb 27, 2016, 10:41:10 PM2/27/16
to ledge...@googlegroups.com
I, too, would like to find out the answer to this question. Still
haven't been able to find a reliable answer on showing *full*
transactions of an account that give me a running balance of the
specific account being queried.

--
Rudd-O
http://rudd-o.com/

Martin Blais

unread,
Feb 28, 2016, 1:42:34 PM2/28/16
to ledger-cli, John Wiegley
So much to say, so little time.

Here: the correct way to do this is to track this in a separate account, like this:

Another way is for you to pay all the expenses and "bill" your roommate by creating and maintaining him/her a dedicated liabilities account. You can just print a register of that account to provide them with the necessary details of their balance.

Trying to keep a single shared pot of money/liabilities requires you to maintain two subaccounts of the real account. It's a PIA and requires discipline. I prefer the two methods above.






--

---
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.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages