Truncating accounts to a fixed depth

91 views
Skip to first unread message

Vikas Rawal

unread,
Sep 18, 2018, 10:29:26 AM9/18/18
to bean...@googlegroups.com
I would like create a trial balance report with accounts truncated to a specific depth (say, two levels).

How could I modify the following trial balance query to achieve this?

SELECT account, sum(position)
GROUP BY account
ORDER BY account;


Vikas

Martin Blais

unread,
Sep 18, 2018, 2:28:07 PM9/18/18
to Beancount
Pull & update:

bean-query $L 'select truncate(account, 3), convert(cost(sum(position)), "USD") group by 1 order by 1'

Also note the existence of the PARENT(), LEAF() and ROOT() functions to act on account name strings.
Moreover, if you have mixed assets, you will want to convert or extract the cost in order to view output that's manageable.




--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CALtzAB280FQqE20Pdkoj%2B7FTa0GCXy8JfDuxmvaNS0Z7ExNGsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

shreedha...@gmail.com

unread,
Sep 19, 2018, 2:23:48 PM9/19/18
to Beancount
Hmm.. How is TRUNCATE(account, 3) different from ROOT(account, 3)?

# Operations on accounts.

class Root(query_compile.EvalFunction):
    "Get the root name(s) of the account."
    __intypes__ = [str, int]

    def __init__(self, operands):
        super().__init__(operands, str)

    def __call__(self, context):
        args = self.eval_args(context)
        return account.root(args[1], args[0])


In accounts.py:
def root(num_components, account_name):
    """Return the first few components of an account's name.

    Args:
      num_components: An integer, the number of components to return.
      account_name: A string, an account name.
    Returns:
      A string, the account root up to 'num_components' components.
    """
    return join(*(split(account_name)[:num_components]))


Thanks

Martin Blais

unread,
Sep 19, 2018, 2:38:14 PM9/19/18
to Beancount
Ah! You're right. I hadn't noticed my version of root already takes a number.
I'll remove TRUNCATE() you don't need it. Use ROOT()


Reply all
Reply to author
Forward
0 new messages