Hi Mario,

I bookmarked this, as I thought it was a really nice, simple yet tricky challenge for all of our plain text accounting tools.

It's not so easy. Here's my attempt using hledger, the one I know best. I can't report "cost per one" or "cost per day" except with the print command at the end. To get the report you wanted, I would need to write some custom reporting code - a haskell script for hledger, or a python script for ledger or beancount.

The below will be mangled if you are not viewing this message as HTML, and probably even if you are, so I've also posted it at:
https://gist.github.com/simonmichael/9873de4158bd399ce95e6b5a59685069 ).


$ cat c.j
2016/06/13 Grocery Store
    Expenses:Food    6.00 eggs @@ $1.20
    Expenses:Food    2.00 Milk @ $0.46
    Expenses:Food    1.00 Water @ $0.19
    Assets:Checking

2016/06/16 Grocery Store
    Expenses:Food    1 Milk @ $0.46
    Expenses:Food    1 Water @ $0.19
    Assets:Checking

$ hledger -f c.j bal -YN
Balance changes in 2016:

                 ||                             2016
=================++==================================
 Assets:Checking ||                           $-2.96
 Expenses:Food   || 3.00 Milk, 2.00 Water, 6.00 eggs

$ hledger -f c.j stats | grep Commodities
Commodities              : 4 ($, Milk, Water, eggs)

$ for c in eggs milk water; do hledger -f c.j bal cur:$c -N -DEAT; done
Balance changes in 2016/06/13-2016/06/16:

|| 2016/06/13 2016/06/14 2016/06/15 2016/06/16 Total Average
===============++=====================================================================
Expenses:Food || 6.00 eggs 0 0 0 6.00 eggs 1.50 eggs

Balance changes in 2016/06/13-2016/06/16:

|| 2016/06/13 2016/06/14 2016/06/15 2016/06/16 Total Average
===============++=====================================================================
Expenses:Food || 2.00 Milk 0 0 1.00 Milk 3.00 Milk 0.75 Milk

Balance changes in 2016/06/13-2016/06/16:

|| 2016/06/13 2016/06/14 2016/06/15 2016/06/16 Total Average
===============++=======================================================================
Expenses:Food || 1.00 Water 0 0 1.00 Water 2.00 Water 0.50 Water

$ hledger -f c.j print food
2016/06/13 Grocery Store
    Expenses:Food    6.00 eggs @@ $1.20
    Expenses:Food     2.00 Milk @ $0.46
    Expenses:Food    1.00 Water @ $0.19
    Assets:Checking              $-2.31

2016/06/16 Grocery Store
    Expenses:Food     1.00 Milk @ $0.46
    Expenses:Food    1.00 Water @ $0.19
    Assets:Checking              $-0.65




On 10/16/16 12:10 PM, Mario Rabe wrote:
Hi guys,

I'm yet another noob trying to figure out if ledger fulfills his needs. I
want to track for what I pay money in an item-wise manner. For example in
one week I went to the grocery two times and bought this (receipt sample
data):


2016/06/13 Grocery Store
   Eggs (6 pack)  $1.20
   Milk
      2 x $0.46   $0.92
   Water          $0.19

2016/06/16 Grocery Store
   Milk           $0.46
   Water          $0.19

How can I put that into my journal that I'm able to extract the following
information:

    - How many of each item did I buy in a period of time
    - What did a single item of each cost in average (when I buy eggs at the
    store or at the market they have different prices which shouldn't result in
    a revaluing)
    - How much did I spend for each item in total

Yet I've tried two approaches, but I weren't able yield the result I
wanted. First is to give every item it's own account like this:

alias Food=Expenses:Food

2016/06/13 Grocery Store
     Food:Eggs                                            $1.20
     Food:Milk                                            $0.92
     Food:Water                                           $0.19
     Assets:Checking

2016/06/16 Grocery Store
     Food:Milk                                            $0.46
     Food:Water                                           $0.19
     Assets:Checking

That way I have a nice balance view (ledger -f byaccount.ledger bal -b
2016/06/13 -e 2016/06/19):
               $-2.96  Assets:Checking
                $2.96  Expenses:Food
                $1.20    Eggs
                $1.38    Milk
                $0.38    Water
--------------------
                    0

I know how much I spend in total on an item but I have no clue how many of
them I bought and what a single one cost in average.
Another idea was to exploit the commodity system so every item has it's own
commodity.

2016/06/13 Grocery Store
     Expenses:Food                                            6 eggs @@ $1.20
     Expenses:Food                                            2 Milk @ $0.46
     Expenses:Food                                            1 Water @ $0.19

2016/06/16 Grocery Store
     Expenses:Food                                            1 Milk @ $0.46
     Expenses:Food                                            1 Water @ $0.19


In theory all the information needed should be in the file but I'm lost
querying it...
Here the balance with just a few items:

ledger -f bycommodity.ledger bal -b 2016/06/13 -e 2016/06/19
                  $-3  Assets:Checking
               3 Milk
              2 Water
               6 eggs  Expenses:Food
--------------------
                  $-3
               3 Milk
              2 Water
               6 eggs

As the commodity gets repeated in the super accounts that view gets
unreadable pretty fast. So in the long run all thats left is how much I
spend in total for food:

ledger -f bycommodity.ledger bal -b 2016/06/13 -e 2016/06/19 -V
                  $-3  Assets:Checking
                   $3  Expenses:Food
--------------------
                    0
(Sidequest: where does the rounding come from?)

I tried all ways I could imagine to query registers, commodities and
balances to get what I want but the result isn't really usable. How can I
query the file to get an result like this?

| item  | total count | count per day | cost per one | cost per day | total
|
|-------+-------------+---------------+--------------+--------------+-------|
| Eggs  |           6 |          0.86 |         0.20 |         0.17 |  1.20
|
| Milk  |           3 |          0.42 |         0.46 |         0.20 |  1.38
|
| Water |           2 |          0.28 |         0.19 |         0.06 |  0.38
|
|-------+-------------+---------------+--------------+--------------+-------|
|       |             |               |        total |         0.43 |  2.96
|

The "per day" columns are optional and I won't mind if I have to use two or
three different views to get the information I want. Is there a way to do
this in ledger? And to create such a report on a weekly basis without me
specifying the exact dates, like the weekly register except it contains the
upper information?

Thanks a lot and kind regards

Mario


--

--- 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