QIF Importer

Thomas Baumgart

Jack H. Ostroff

QIF format considered harmful

Generally speaking, the QIF format should be avoided wherever possible. For many reasons, it is a poor choice for transporting financial data. Among other things, QIF suffers from these problems:

  • Lack of standardized format: Different versions of the same program will impart different meanings to the same element.

  • Lack of transaction identifier: Because there is no ID number associated with each transaction, matching duplicate transactions is haphazard at best.

  • Lack of expressiveness: The grammar is really simple, and cannot portray the depth of financial information found in today's financial environment.

This is generally why Intuit stopped supporting QIF input at all with Quicken 2005. If you have the option of getting data some other way, like OFX, always choose that option.

How to import a QIF file

To import a QIF file, first ensure you have a valid KMyMoney file open, then select the FileImportQIF... menu item.

qif importer

The resulting dialog prompts for the QIF filename, allowing you to type in the full path to the file or to locate the file by clicking Browse.

Note that KMyMoney differentiates between the import of a bank statement file and a file with historic data exported from another application. A bank statement file does not necessarily include all the data related to a single bank statement; it may contain only one or a few transactions. The default is to import a bank statement file. In case you are importing data from your previous personal finance manager application, select the appropriate option.

Next, you need to select a QIF Profile for the import. Because there is no universally standard format for a QIF file, different vendors have taken liberties with the format, and introduced their own nuances. The QIF Profile allows KMyMoney to know about the peculiarities of your file. In general, the default QIF profile should work with most QIF files. In some cases it might be necessary to use a modified QIF profile. See the next section for more details on that subject.

Click Import to import the QIF file.

KMyMoney will start scanning the file to determine the formats used to represent dates and numbers. In case it cannot determine a date format unambiguously, KMyMoney will ask the user to select one from the list of possible date formats.

Next, KMyMoney imports the data and creates all necessary objects, such as payee information, account and category records, and stock price information. Wherever possible, existing transactions will be matched against the imported information, to avoid duplicate transactions. A progress bar is shown and updated during the import process.

In case KMyMoney could not detect the name of the account to be imported, the user will be asked to select the account into which the data should be imported. If the account does not already exist in your file, a new account can be created by clicking Create.

At the end of the import, KMyMoney shows a statement import statistics window.

qif import statement statistics

After importing, all of the imported transactions will be shown with a yellow background in the Ledgers View. In case KMyMoney was able to match an imported transaction with an already existing transaction, the background is shown in light green.

Note

The colors used to mark imported and matched transactions are customizable and may be different in your environment.

The next step is to verify the imported data and accept all the imported transactions. This is a general process and also applies to imports from other sources. It is similar to the process for matched transactions. All imported transactions are marked in the ledger with an imported icon. Once you Accept the transaction, it is no longer marked as Imported.

Transaction matching

As noted previously, one of the major drawbacks of the QIF format is the lack of a unique identifier for each transaction. Thus, if you import a QIF file and some of the transactions are already in your ledger, you may get duplicates. KMyMoney attempts to get around this by looking for transactions that look similar to those you already have. If it finds something that looks like the same transaction, it will match the apparent duplicate.

This can be a problem if you have transactions that look very similar but are actually different. In this case, you can unmatch those transactions later in the Ledger View.

Writing an import filter

Sometimes you may have data in a custom format, like comma-separated-values (CSV) or something else unique to your situation. As of version 4.6, KMyMoney includes a CSV Importer Plugin, but you can still import other types of files into KMyMoney using a QIF Import Filter. A filter is a custom program you write which takes your special file as input, and produces a QIF file as output. This can be a shell script, a perl script, a compiled program written in C/C++, or anything else you can dream of, as long as the system can run it. The filter will be run with the input file as stdin and stdout is assumed to be a valid qif file to pass on to the actual QIF importer.

To use a filter, edit your favorite QIF Profile or create a new one (see the next section for details on QIF Profiles,) and select the Filter tab. Enter the full path to your filter program in the Input filter location field, or click the browse icon next to the field and navigate to the filter in the File Open... dialog. Then, whenever you do a QIF import using this profile, the file you select for importing will be run through your filter first. Note that the filter location field contains the full path to the filter program or script, but can also include command line parameters for the program.

Next, if you want the File Open... dialog where you choose the file to input to have a filter for your specific file type, enter a comma separated list of file filters (such as *.abc,*.xyz) in the Input filter file type field. With the above example, when you open a file for import using this profile, you will only see files ending in abc or xyz. If you leave the field empty, no name filtering will be done, and you will see all files.

A common problem is to convert a list of comma-separated-values into a QIF file. Prior to the addition of KMyMoney's CSV Importer plugin, this would have been a textbook case for the awk tool. We still use this example here, just to show a sample of how the import filter process works. Create a script called csv2qif.awk, with the following two lines as contents:

    BEGIN { FS=","; print "!Type:Bank" }

    { print "D"$1; print "T"$2; print "N"$3; print "P"$4; print "M"$5; print "^" }

Then, change the QIF keys (D,T,N,P,M) to match the order of the columns in your CSV data. Set the input filter to awk -f csv2qif.awk.

Another problem sometimes arises in the encoding of QIF files. KMyMoney expects files to be UTF8 encoded. If your file is encoded in something else, it can be useful to convert it to UTF8. For example to convert it from iso-8859-1, you would set the input filter to recode iso-8859-1..utf-8.

Special KMyMoney QIF extensions

As already mentioned, one of the major drawbacks of the QIF format is the lack of a unique identifier for each transaction. If you are writing your own QIF file creator (or filter, as described above,) you can overcome this problem. KMyMoney supports the '#' field. The importer will interpret this as a unique transaction ID, and disregard the record if the transaction is already in the system.