Difference between revisions of "Merging GnuCash Files"

From GnuCash
Jump to: navigation, search
(First draft)
 
(Added footnotes)
Line 18: Line 18:
 
== Test that the transactions were exported correctly ==
 
== Test that the transactions were exported correctly ==
  
We test it by importing the transactions back into an empty 2001 file.
+
We test it by importing the transactions back into an empty 2001 file.<ref>If you can successfully import transactions into the file it was exported from you prove that your CSV file is correct. This step is necessary because it is much harder to detect errors in the CSV once you import it into <code>2000.gnucash</code> and transactions from both years are merged.</ref>
  
 
* Make a copy of file <code>2001_01_accounts.gnucash</code> with the new name <code>2001_02_accounts_imported_into_itself.gnucash</code> and open it.
 
* Make a copy of file <code>2001_01_accounts.gnucash</code> with the new name <code>2001_02_accounts_imported_into_itself.gnucash</code> and open it.
 
* Select File→Import→Import Transactions from CSV… Select the file <code>2001_02_transactions_noduplicates.csv</code>. On the Import Preview page, under Load and Save Settings, select ‘GnuCash Export Format’. On the Match Transactions page, make sure all lines have ‘New, already balanced’ in the rightmost ‘Additional Comments’ column. If a line has other comments then manually fix the problem in the CSV file.
 
* Select File→Import→Import Transactions from CSV… Select the file <code>2001_02_transactions_noduplicates.csv</code>. On the Import Preview page, under Load and Save Settings, select ‘GnuCash Export Format’. On the Match Transactions page, make sure all lines have ‘New, already balanced’ in the rightmost ‘Additional Comments’ column. If a line has other comments then manually fix the problem in the CSV file.
* Open a second instance of GnuCash and load <code>2001.gnucash</code>. Make sure that in the two GnuCash windows on the Account tab the values in the Total column are identical for accounts on the lowest level. If the Total for a higher level account is different it does not matter because it can be caused by missing prices. If the two windows are identical then you can be sure that <code>2001_02_transactions_noduplicates.csv</code> correctly contains all your transactions from 2001.
+
* Open a second instance of GnuCash<ref>On Linux you can simply start GnuCash again to open a second instance. On Windows you have to start GnuCash with the command <code>gnucash.exe --nofile</code></ref> and load <code>2001.gnucash</code>. Make sure that in the two GnuCash windows on the Account tab the values in the Total column are identical for accounts on the lowest level. If the Total for a higher level account is different it does not matter because it can be caused by missing commodity prices. If the two windows are identical then you can be sure that <code>2001_02_transactions_noduplicates.csv</code> correctly contains all your transactions from 2001.
  
 
== Comparing Accounts between years ==
 
== Comparing Accounts between years ==
Line 51: Line 51:
 
** the values in the Total column
 
** the values in the Total column
 
** are identical for all accounts
 
** are identical for all accounts
** under Assets on the lowest level. If the Total for a higher level account is different it does not matter because it can be caused by missing prices.
+
** under Assets on the lowest level. If the Total for a higher level account is different it does not matter because it can be caused by missing commodity prices.
 
* To make the totals equal, you might need to delete the opening balance transactions.
 
* To make the totals equal, you might need to delete the opening balance transactions.
 
* Open each Equity account and make sure that if they have opening balance transactions from 2001 it really makes sense to keep them in the merged file. Most of the time they should be deleted, because ending balances for 2000 will already be in the merged file.
 
* Open each Equity account and make sure that if they have opening balance transactions from 2001 it really makes sense to keep them in the merged file. Most of the time they should be deleted, because ending balances for 2000 will already be in the merged file.
 
* Open each Liability account and make sure their ending balance is equal to the ending balance in <code>2001.gnucash</code>.
 
* Open each Liability account and make sure their ending balance is equal to the ending balance in <code>2001.gnucash</code>.

Revision as of 21:19, 9 July 2023

These are the steps I took to successfully merge two GnuCash files containing transactions for two separate years. Below I use 2000.gnucash and 2001.gnucash, but obviously you can use any two years. We will take 2000.gnucash and import into it all transactions from 2001.

This process does not merge any Business data.

Prerequisites:

  • I successfully used GnuCash 5.0, 5.1, and 5.3 for this process.
  • VSCode with the Rainbow CSV plugin.

Exporting accounts and transactions from 2001

  • Create a separate ‘merge folder’ to store the temporary files required for the merge process.[1]
  • Make a copy of 2001.gnucash into the ‘merge folder’ so you don’t modify the original file.
  • Open 2001.gnucash in read-only mode, select File→Export→Export Accounts and name the file 2001_01_accounts.gnucash.
  • Select File→Export→Export Account Tree to CSV… Accept default settings (comma separated file) and name the file 2001_03_account_tree.csv.
  • Select File→Export→Export Transactions to CSV… Accept default settings (comma separated file) and on the ‘Account Selection’ page select the topmost Assets account (under which you have all your assets, like bank accounts, cash, stocks, etc.) and Expenses and click the Select Subaccounts button. Click Next and name the file 2001_02_transactions.csv.
  • Open VSCode and make sure the Rainbow CSV plugin is installed. Open 2001_02_transactions.csv in VSCode, press CTRL+SHIFT+P, search for ‘Rainbow CSV: RBQL’ and select it. In the new tab check ‘Input table has header’ at the bottom, and overwrite the Example query with SELECT DISTINCT * ORDER BY a2. Click Run, a new tab will be opened. Save As this tab with the name 2001_02_transactions_noduplicates.csv.

Test that the transactions were exported correctly

We test it by importing the transactions back into an empty 2001 file.[2]

  • Make a copy of file 2001_01_accounts.gnucash with the new name 2001_02_accounts_imported_into_itself.gnucash and open it.
  • Select File→Import→Import Transactions from CSV… Select the file 2001_02_transactions_noduplicates.csv. On the Import Preview page, under Load and Save Settings, select ‘GnuCash Export Format’. On the Match Transactions page, make sure all lines have ‘New, already balanced’ in the rightmost ‘Additional Comments’ column. If a line has other comments then manually fix the problem in the CSV file.
  • Open a second instance of GnuCash[3] and load 2001.gnucash. Make sure that in the two GnuCash windows on the Account tab the values in the Total column are identical for accounts on the lowest level. If the Total for a higher level account is different it does not matter because it can be caused by missing commodity prices. If the two windows are identical then you can be sure that 2001_02_transactions_noduplicates.csv correctly contains all your transactions from 2001.

Comparing Accounts between years

  • Make a copy of 2000.gnucash into the ‘merge folder’ under the name 2001_03_before_import.gnucash so you don’t modify the original file.
  • Open 2001_03_before_import.gnucash then select File→Export→Export Account Tree to CSV… Accept default settings (comma separated file) and name the file 2001_03_previous_account_tree.csv.
  • Make a copy of 2001_03_previous_account_tree.csv with new name 2001_03_previous_account_tree_sorted.csv.
  • Make a copy of 2001_03_account_tree.csv with new name 2001_03_account_tree_sorted.csv.
  • Open the above two copied files in VSCode and do the following in both files: Select All then press CTRL+SHIFT+P, search for Sort Lines Ascending and execute.
  • Activate the tab of 2001_03_account_tree_sorted.csv then press CTRL+SHIFT+P, search for File: Compare Active File With… and execute. Select 2001_03_previous_account_tree_sorted.csv and press Enter. A new tab should open, comparing the two files. 2001_03_previous_account_tree_sorted.csv should be on the right.
  • In this tab you see the accounts you used in 2000 on the left hand side. The idea is that all accounts on the left must exist on the right. If you find missing accounts then copy their line from 2001_03_previous_account_tree_sorted.csv into a new file called 2001_03_account_tree_tobeimported.csv. If your account names contain international characters then you have to find out what encoding will work best. It seems to depend on the language you use GnuCash in.
  • If some accounts exist on boths sides but their account settings are different, you can migrate these settings, as well. In the CSV the last 3 columns are Hidden, Tax Info, Placeholder, each with a value of T (true) or F (false). Open 2001_03_before_import.gnucash in GnuCash and change the settings manually.

Merging securities

  • Open two instances of GnuCash with the files 2001.gnucash and 2001_03_before_import.gnucash. Open Tools→Security Editor and make sure all securities in 2001.gnucash also exist in 2001_03_before_import.gnucash. Manually create the missing securities.

Importing Accounts

  • You can close 2001.gnucash and keep open 2001_03_before_import.gnucash. In this file select File→Import→Import Accounts from CSV… Select 2001_03_account_tree_tobeimported.csv to import and accept default settings. Ideally, on the last screen GnuCash will say that the number of accounts import equals the number of lines in your CSV file, and 0 accounts were updated (you’ve already done the updates manually).

Importing Transactions

  • Make a copy of 2001_03_before_import.gnucash with new name 2001_04_imported.gnucash.
  • Open 2001_04_imported.gnucash and select File→Import→Import Transactions from CSV… Select the file 2001_02_transactions_noduplicates.csv. On the Import Preview page, under Load and Save Settings, select ‘GnuCash Export Format’. On the Match Import and GnuCash accounts page make sure that the account names in both columns are identical and there is no ‘No Linked Account’ message in the right hand side column. On the Match Transactions page, ideally, all lines will have ‘New, already balanced’ in the rightmost ‘Additional Comments’ column. For those that don’t, you have to manually decide what GnuCash should do with that particular line: Update an existing transaction and reconcile it (check the box in the U+C column), or skip the import (do not check any columns).
  • Open a second instance of GnuCash and load 2001.gnucash in read-only mode. Make sure that in the two GnuCash windows
    • on the Account tab
    • the values in the Total column
    • are identical for all accounts
    • under Assets on the lowest level. If the Total for a higher level account is different it does not matter because it can be caused by missing commodity prices.
  • To make the totals equal, you might need to delete the opening balance transactions.
  • Open each Equity account and make sure that if they have opening balance transactions from 2001 it really makes sense to keep them in the merged file. Most of the time they should be deleted, because ending balances for 2000 will already be in the merged file.
  • Open each Liability account and make sure their ending balance is equal to the ending balance in 2001.gnucash.
  • At the end of this process, you will have many files in this folder corresponding to each step, so if you discover any errors at the end then you don't have to start from scratch but only go back to the problematic step.
  • If you can successfully import transactions into the file it was exported from you prove that your CSV file is correct. This step is necessary because it is much harder to detect errors in the CSV once you import it into 2000.gnucash and transactions from both years are merged.
  • On Linux you can simply start GnuCash again to open a second instance. On Windows you have to start GnuCash with the command gnucash.exe --nofile
  • Retrieved from "https://code.gnucash.org/wiki/index.php?title=Merging_GnuCash_Files&oldid=21766"