Hi Simon, At Sun, 5 Oct 2014 15:17:32 -1000, Simon Michael wrote: > > Thanks! I have questions: > > On Oct 2, 2014, at 7:18 PM, Erik Hetzner <[email protected]> wrote: > > Sure, here Is an example. This is one expense account: > > > > $ ledger bal ^Expenses:Erik:Bicycle -E -p "monthly from 2014 until last > > month" > > $267.64 Expenses:Erik:Bicycle > > > > That is my total bike spending in 2014. > > I'm confused by the "monthly" - my guess it is has no effect in these ledger > balance commands ?
Whoops! Yes, it seems to be completely meaningless. :) > > The number I am looking for is > > $267.64 / 9 => $29.74, my average monthly spending in 2014 (until > > Sept) on bike expenses. So this command gives me what I am looking > > for: > > > > $ ledger bal ^Expenses:Erik:Bicycle -E -p "monthly from 2014 until last > > month" --display-total "(display_total>0 or display_total<0) ? > > display_total/(to_int(format_datetime(d, '%m')) - 1) : ''" > > $29.74 Expenses:Erik:Bicycle > > Nifty, could you explain the divisor expression a little more ? I don't quite > understand how it's working. Sure, no problem. The first check (display_total>0 or display_total<0) is to avoid divide by zero. format_datetime(d, '%m') returns the current month, e.g. 10 for October. to_int makes it an int, - 1 yields 9. So ledger divides the total by 9, the total months we are adding up. It's a total hack, as you can see. It only works because we are starting at the beginning of the year and going to last month. You could of course pass in the divisor manually and avoid all the hacky magic. > > Moreover, if I don't restrict it to that one account, it works for all > > accounts, giving me my average monthly spending in each expense > > category for the year. > > > > Your command gives me: > > > > $ hledger reg -MAE '^expenses:erik:bicycle$' --depth 2 -p "monthly from > > 2014 until last month" > > 2014/01/01 - 2014/01/31 Expenses:Erik $22.00 > > $22.00 > > 2014/02/01 - 2014/02/28 Expenses:Erik $23.07 > > $22.54 > > 2014/03/01 - 2014/03/31 Expenses:Erik $37.24 > > $27.44 > > 2014/04/01 - 2014/04/30 Expenses:Erik $157.00 > > $59.83 > > 2014/05/01 - 2014/05/31 0 > > $47.86 > > 2014/06/01 - 2014/06/30 0 > > $39.89 > > 2014/07/01 - 2014/07/31 Expenses:Erik $28.33 > > $38.23 > > 2014/08/01 - 2014/08/31 0 > > $33.46 > > 2014/09/01 - 2014/09/30 0 > > $29.74 > > > > which does give me the right answer at the end ($29.74) but outputs a > > lot more and only works on one account. > > Right, I forgot to mention "8. the average you want is the last number in the > running total column". No problem! Thanks for the clue on how to do this without that awful output display hack. > > ledger doesn't seem to work properly: > > > > $ ledger reg -MAE '^expenses:erik:bicycle$' --depth 2 -p "monthly from > > 2014 until last month" > > 14-May-01 - 14-May-31 <None> 0 > > $47.86 > > 14-Jun-01 - 14-Jun-30 <None> 0 > > $39.88 > > You might get a better result if you say --depth 3, the depth of your account > of interest. IIRC I improved the aggregation of depth-clipped postings in > hledger register. Good point, though I still get the wrong answer: $ ledger reg -MAE '^expenses:erik:bicycle$' -p "from 2014 until last month" -f finances/ledger.lgr 14-Jan-01 - 14-Jan-31 Expenses:Erik:Bicycle $22.00 $22.00 14-Feb-01 - 14-Feb-28 Expenses:Erik:Bicycle $23.07 $22.54 14-Mar-01 - 14-Mar-31 Expenses:Erik:Bicycle $37.24 $27.44 14-Apr-01 - 14-Apr-30 Expenses:Erik:Bicycle $157.00 $59.83 14-May-01 - 14-May-31 <None> 0 $47.86 14-Jun-01 - 14-Jun-30 <None> 0 $39.88 14-Jul-01 - 14-Jul-31 Expenses:Erik:Bicycle $28.33 $38.23 This seems to be because I had no bike related expenses in the last 2 months of the period (August and September), so the average is not taking those months into account. best, Erik -- Sent from my free software system <http://fsf.org/>. -- --- 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.
