Step zero is to backup you GnuCash file before fussing with it. :)
First, make sure your balance sheet reports include all accounts, including hidden accounts. It's easy to open a saved report and not realize that you've since created a new account or two totaling $10,000.
Then, you can find what went wrong by using the Trial Balance report (Reports > Income and Expense > Trial Balance). In the report options, go to top tab Accounts > check Show Hidden Accounts, then click Apply. If the trial balance is out of balance today (debits and credits two different totals), then you probably have a broken transaction.
In the General tab, change the Date of Report on the trial balance. Set it to Jan. 1, 2021. If it was out of balance then, you know the transaction that broke is older. If not, you know it was a newer transaction. If Jan 2021 was in balance, set the date to June 30, 2021. If not, set the date to January 1, 2020. You can keep changing the report date. Each time you check another date, you can narrow down when the problem occurred. Split the remaining period in approximately half each time. Eventually, you will find the exact date of the broken transaction. So, you might see that on Oct. 2, 2021, the trial balance was in balance, and on Oct. 3, 2021, the trial balance was out of balance. Then you know the problem started on Oct. 3. Subtract total credits from total debits on the trial balance to find out how much the difference was on that date. You may have multiple broken transactions, so don't just assume the full $10,000 happened on one day.
Next, for the date when the problem started, run the transactions for that date.
- I like to use Find (Edit > Find) and set the search criteria as Date Posted - is on - Oct. 3, 2021. It doesn't allow you to edit options easily, but it has a very clean display and it is quick to use.
- Alternatively, use a Reports > Transaction Report. Again, for this you will need to include hidden accounts, then use the Select All Accounts button. Set the date as the date the problem started, and change the Sorting tab to have as Primary Key - Register Order. This one allows you to change the dates in report options and hit Apply.
Look over the transactions for that date. See if any match in amount to the difference between your debits and credits on the trial balance on that date. If you only have four transactions, and one has part that matches the amount, then you've got it. Somehow, even if it looks like that transaction is balanced, something about it is broken. Make note of what it was, then:
- delete that transaction
- refresh the trial balance for that date, confirm that it now balances
- go back into one of your registers (that stock register, if it was a stock transaction) and recreate that transaction, making sure the transaction balances
- refresh the trial balance again, confirming that the trial balance still balances
- set the trial balance to today's date and see if it still balance; this determines if you need to repeat the finding process for a later date or if your books are now balanced
Once your books are balanced, go back to December 21, 2021 and see if your old book closing transactions still work or if you need to fix them. Making this correction might mean that there is now more or less capital gain (or some other income/loss difference) in your 2021 books, which means the closing transactions might need to be corrected. The easiest way might just be to delete those closing transactions and recreate them, but that is up to your judgement.
Source: I don't close my books, but I had to go through this same process to fix them. I had two stock trading transactions that were broken. I could have sworn there was something on the GnuCash website that helped me, but I can't find it now.