Skip to content

Commit

Permalink
;examples:multi-year: how to show year-end balances in closed files [s…
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael authored and adept committed Mar 8, 2024
1 parent b41aa27 commit f27ecae
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
14 changes: 14 additions & 0 deletions examples/multi-year/2021.journal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; 2021.journal

2021-06-01 opening balances ; start:2021
assets 20 = 20
equity:start

2021-07-01 income
income
assets 1

2021-12-31 closing balances ; start:2022
assets -21 = 0
equity:start

14 changes: 14 additions & 0 deletions examples/multi-year/2022.journal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; 2022.journal

2022-01-01 opening balances ; start:2022
assets 21 = 21
equity:start

2022-07-01 income
income
assets 1

2022-12-31 closing balances ; start:2023
assets -22 = 0
equity:start

10 changes: 10 additions & 0 deletions examples/multi-year/2023.journal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; 2023.journal

2023-01-01 opening balances ; start:2023
assets 22 = 22
equity:start

2023-07-01 income
income
assets 1

4 changes: 4 additions & 0 deletions examples/multi-year/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Multiple yearly journal files, demonstrating the tags and commands
suggested in the [close command's doc](https://hledger.org/dev/hledger.html#example-exclude-openingclosing-transactions>)
for flexible multi-year reporting.
See `reports`.
14 changes: 14 additions & 0 deletions examples/multi-year/reports
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh

# Suppressing redundant starting/ending balances transactions as suggested in
# https://hledger.org/dev/hledger.html#example-exclude-openingclosing-transactions .
# All of these will show the year-end balances correctly.
# In each case, we exclude all transactions tagged with start: except the earliest.

hledger bs -Y -f 2021.journal -f 2022.journal -f 2023.journal expr:'tag:start=2021 or not tag:start'
hledger bs -Y -f 2021.journal -f 2022.journal expr:'tag:start=2021 or not tag:start'
hledger bs -Y -f 2022.journal -f 2023.journal expr:'tag:start=2022 or not tag:start'
hledger bs -Y -f 2021.journal expr:'tag:start=2021 or not tag:start'
hledger bs -Y -f 2022.journal expr:'tag:start=2022 or not tag:start'
hledger bs -Y -f 2023.journal # unclosed file, no query needed

2 changes: 1 addition & 1 deletion hledger/Hledger/Cli/Commands/Close.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ $ hledger -f 2022.journal bs not:desc:'closing balances'
When combining files for multi-year reports, for some reports (eg a yearly balance sheet)
you may need to suppress all opening/closing transactions except the first.
This is a bit awkward if you also want to be able to choose any range of year files,
but here is a way, using tags:
but here is a way, using tags (full example [here](https://github.com/simonmichael/hledger/tree/master/examples/multi-year/)):

```journal
; 2021.journal
Expand Down

0 comments on commit f27ecae

Please sign in to comment.