Hello everyone,
I'm looking for a way to provide a custom date interval to an hledger command.
My use case is the following:
I have a CLI tool helping me decide for every week which "budget month" it is part of (e.g., when a week overlaps two months, it decides which month the week belongs to). I don't like splitting weeks, and this is the solution I've come up with.
Now, I would love to use hledger's reporting capabilities with a monthly query hledger --no-conf --file ~/path/to/my-journal.journal incomestatement -p 2024 -M
to reflect this. Right now, the expenses will be tied to their respective month.
Is their any way to achieve this?
Let me know if anything is not clear, I'll be happy to provide more details.
I guess you want to keep the transaction dates accurate. But I suppose you could record adjusted budgeting dates as https://hledger.org/1.52/hledger.html#secondary-dates, and run your budget reports with --date2 ?
Hi,
Thanks for the prompt reply and many more thanks for the awesome tool that is Hledger!
I'm not sure secondary date is what I'm looking for. From what I understand from the page you linked, secondary date allow to link two dates to a single posting.
My goal is not to keep transaction dates accurate.
My goal is to group budget week in their "correct" budget month.
Let's take 2024 as an example. My tool output a Json dividing a year into budget month as I explained earlier.
As you can see, the first week of February starts in January. What I would really want is for Hledger to use this timeframe when doing a query that spans over months (e.g., January runs from 01-01 to 01-28)
I think this implies that you can't or do not want to use '-b' /'-e' with your custom dates. Am I right? If I am - could you elaborate why?
Perhaps something like this would work: hledger run with a script that your tool genrated. Script will contain 12 commands, one per "month", with custom begin/end dates, and perhaps with --total-only
I did not know about the -b/-e flags. I'm currently using -p "start_date..end_date" to specify the date period for my queries. Is there any difference between the two approaches?
With the current output of my tool, I'm able to generate a monthly query that includes the correct weeks. My goal now is to glue the queries together to have a yearly report, divided by my budget month.
EDIT: actually CompoundBalanceCommandSpec does not specify reporting periods, ignore me.
incomestatement is just a thin wrapper around compoundBalanceCommand. I feel like it should be easy to write a new custom script/custom binary (a-la those available in hledger/scripts) that read your periods from args or file, constructs CompoundBalanceCommandSpecwith your custom periods and feeds it to compoundBalanceCommand. See hledger/bin/hledger-report1.hs in the repo for a skeleton code that could be used as a starting point, if you are so inclined.
This is probably easier that trying to add some sort of generic "custom report period spec" to hledger which by necessity would have to be more flexible and more general than what's necessary for your specific case.
I was very bummed to read your edit @adept but it is what it is.
Since there is no easy way to pass a custom date period to the balance command, I gave up and documented the limitation in my reporting tool. This is acceptable as I can still get the values I need, just not in a single query.
Out of curiosity, how hard do you think it might be to allow the balance command to expose a custom reporting period? I'm a complete noob in Haskell (i.e., that is I never wrote a single line of code in this language) so I would probably not able to contribute anyway.
My brain tells me there is a way to do this, but for two reasons it cannot brain enough to get to the "way to do this"
I cannot seem to clearly understand what the ask is.
It's too morning where I am sorry
I'll take a stab at answering anyways, but first I'll share my assumptions on understanding the ask.
First assumption: you're budgeting in weeks. — if this holds true, then the assumption follows that you have something like this somewhere
~ weekly
expenses 20 cur
assets
If this, then budget -W could help, no?
Second assumption: there's no budget, but weeks are just broken up into what looks like W22, W23, …and so on. Maybe budgeting is done outside the PTA tool. Here, we would want the balance only
In this case, [report] -W should work, no? I see HLedger allows bse -W
If these assumptions are wrong, please guide me. But I strongly believe there is some solution.
Hello @igbanam,
Firstly, I don't use the budget function (yet) provided by Hledger.
Secondly, the issue does not lie in the usage of -W but in -M.
My goal is to compute from a Hledger statement a single table, divided by my budget months and not by "regular" month.
Taking 2024 as an example:
[W1][W2][W3][W4][W5]...
[January ][February]
In my budgeting rules, the entirety of W5 is part of February.
When using -M, W5 will be split (as expected) between January and February, which is not what I want.
I think the date2 workaround I suggested would achieve it. You'd manually (or with a script) add a secondary date, in the desired budgeting month, to transactions which need it.
Indeed. I was considering as an option to create an intermediary journal with all overlapping transactions moved to their correct budget month. Using date2 might be simpler then. Thanks for the reminder.