In last week’s blog posting I explained how I calculated average weekly grocery expenses over two different periods of time. I used an hledger command to generate the weekly amounts in a csv file. I then opened the file in a spreadsheet and calculated the weekly averages.
I have a long history of working with spreadsheets, so it was very natural for me to use one as a tool for finding the averages.
As I was doing this, however, it occurred to me that hledger could probably calculate the averages. However, I knew that I could get the answer in the spreadsheet, so that’s what I stuck with.
This last week, however, I decided to revisit the question. And I am glad that I did. There is an hledger flag –average, which does the job nicely. One thing that tripped me up was that the –average flag works with the reg command, but not the areg command. Once I had that straightened out, I used the following command:
hledger reg expenses:groceries -b1-1 -e7-27 --average --weekly
As a result, I got each week’s grocery expense and a running average expense for 2026 from the beginning of the year until the time we dropped the meal kit delivery service. Here are the first few lines of the output:
2026-01-01..2026-01-07 expenses:groceries $112.68 $112.68 2026-01-08..2026-01-14 expenses:groceries $210.85 $161.76 2026-01-15..2026-01-21 expenses:groceries $214.68 $179.40
In the output above, I really like how hledger caclulates a running average in the last column. That is, the second line has the two week average, the third line has the average weekly expense for the first three weeks, and so on.
Next, I wanted to find the grocery expenses from July 28 forward, so I modified the above command to:
hledger reg expenses:groceries -b7-28 -e9-17 --average --weekly
This gave me the weekly totals and running weekly averages for grocery expenses after we dropped the delivery meal kit service. Just in case you missed last week’s blog, there was a significant savings in our case.
In short, the hledger –average flag does the job just fine. And as much as I am comfortable with spreadsheets, I think it’s faster to use the –average flag.