On Thu, Oct 2, 2014 at 2:50 PM, Simon Michael <[email protected]> wrote:

> On 9/26/14 8:59 PM, Erik Hetzner wrote:
>
>> On Thu, 25 Sep 2014 10:01:59 -0700
>>> Erik Hetzner <[email protected]> wrote:
>>>
>>>> This is what I came up with to get average monthly expenses over a
>>>> time period.
>>>>
>>>>    ledger bal ^Expenses -E -p "monthly from 2014 until this month"
>>>> --display-total "(display_total>0 or display_total<0) ?
>>>> display_total/(to_int(format_datetime(d, '%m')) - 1) : ''"
>>>>
>>>
>> I should clarify that the above is a bit of a hack and will only work
>> if you are averaging starting at the beginning of the year until now,
>> because it divides by the number of the current month.
>>
>> If somebody has a better way to do it I would love to know. Am I the
>> only person who wants to know what my average spending in a category
>> is per month?
>>
>
> Far from it - everyone wants this sooner or later. When we discussed this
> on #ledger in July, my answer was:
>
> ledger reg -MAE '^some:account$' --depth 2
>
> 1. for each account you're interested in, one at a time
> 2. limiting the report depth to that of the account
>   (to get a single report line per period)
> 3. ^ and $ to ensure precise account matching
> 4. -E to show per-period average not per-line average
> 5. -M for monthly, -W for weekly etc.
> 6. ledger 3 (or hledger), not ledger 2
> 7. with current ledger 3, ensure there's some data (maybe in each
>    period ?) to avoid a segfault bug
>
> Does the more complicated command you gave have advantages ? Maybe it
> shows all accounts at once ? I don't have a ledger-compatible journal here
> that avoids 7, so sample output would be nice to see.


On a related note, just toying with how this would look in my proposed
SQL-like query language, it would require nested statements support:

SELECT
 root_account, AVG(balance)
FROM (
 SELECT
   MAXDEPTH(account, 2) as root_account
   MONTH(date) as month,
   SUM(change) as balance
 WHERE date > 2014-01-01
 GROUP BY root_account, month
)
GROUP BY root_account

-- 

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

Reply via email to