MySQL is Way Cooler than Quicken

Date Posted: October 30th, 2009

You’ve been keeping track of your expenses for the past month; now you want to analyze the data.

I used to use Quicken and Aaron used Mint.com, and while these tools are convenient and pretty, they don’t really work well for us. One annoyance is that these tools use credit card statements and the like to populate the tables. What do you do when you buy lightbulbs and groceries at the grocery store? Are the lightbulbs also food? You also probably didn’t keep the receipt so you don’t know how much they cost. Because of that, the graphs are never accurate. Another annoyance is that Quicken had a difficult time actually pulling my information from the different institutions. I got tired of it quickly and didn’t buy the next year’s upgrade.

MySQL to the rescue. Admittedly if you’re not comfortable with computers this maybe a bit scary to use, but if you want to be able to answer the questions you have about your finances and don’t care about a pretty interface it could be the right tool for you. This is what we use to analyze our financial data, and I’ll show you how to use it too.

MySQL is a relational database management system, meaning that data within it is stored as tables and the relationships between tables are also shown as tables. For this exercise the multiple tables thing isn’t important. What is important is that with RDBMSs you can ask whatever questions you want about the tables, as long as you form those questions in the query language. We only have one table, so this is how we’re using MySQL.

Step 1) Copy the Spreadsheet

You have your table in Google Docs. The first step is to make sure your columns are in the right format. MySQL will complain if they aren’t.

  • Amount column values must not have a preceding $. (Notice the spreadsheet picture)
  • Date must be in YYYY-MM-DD format

Now that your format’s all set, copy the cells with the information. If you have a “Cleared?” column don’t copy that. Also, don’t copy titles. You’ll be making special titles soon enough. Throughout the rest of this tutorial I’ll be assuming you have the same columns that I do.

step1-googledocs

Step 2) Paste into Text Editor

I’m using a Mac, so I copied the text into pico in the terminal. Save it as a .txt file. Mine is called ledger.txt. Make sure you use a text editor and not a word-processor. Word-processors will add information to the text that you DO NOT WANT. If you’re using a Windows machine use notepad.

step2-texteditor

Step 3) Get XAMPP

The easiest way to get MySQL onto your computer is to use XAMPP. If you install MySQL directly you’ll have to do some configuration magic that is a pain, and really unnecessary for the task at hand. You aren’t setting up a production web server, so you don’t have to worry about security or anything. XAMPP is as close to plug and play as you get with this. It’s also free.

You can get XAMPP here. Follow the instructions on the site for how to install and get started for your operating system.

Step 4) Set up DB and Import Data

Open up a terminal (on windows: run –> cmd) and move to the XAMPP directory. Then move to xamppfiles; then to bin. The full path of the bin directory for me is:
/Applications/XAMPP/xamppfiles/bin

The command mysql should be in this directory. Stuff in bold is stuff you type.

Open MySQL:

$ ./mysql -u root

“-u root” just means that you are logging in as the user “root”.

You should get the following prompt:

mysql>

Now that you’re in, the next step is to create your database and use it.

mysql> create database finances;
Query OK, 1 row affected (0.00 sec)


mysql>use finances;
Database changed

Next create your table. Again, this is assuming you have the same columns.

mysql> CREATE TABLE 'expenses' (
-> 'date' date default NULL,
-> 'store' varchar(255) default NULL,
-> 'item' varchar(255) default NULL,
-> 'tag' varchar(255) default NULL,
-> 'subcategory' varchar(255) default NULL,
-> 'amount' decimal(10,2) default NULL,
-> 'source' varchar(255) default NULL
-> );
Query OK, 0 rows affected (0.13 sec)

mysql> delete from expenses;
Query OK, 0 rows affected (0.00 sec)

mysql> load data local infile '/Users/mrio/ledger.txt' into table expenses;
Query OK, 30 rows affected, 7 warnings (0.05 sec)
Records: 30 Deleted: 0 Skipped: 0 Warnings: 7

Here’s an easy to copy and paste version of the Create table command:
CREATE TABLE 'expenses' ( 'date' date default NULL, 'store' varchar(255) default NULL, 'item' varchar(255) default NULL, 'tag' varchar(255) default NULL, 'subcategory' varchar(255) default NULL, 'amount' decimal(10,2) default NULL, 'source' varchar(255) default NULL );

In case you’re wondering what each command does:

“create table” creates the table into which your data goes.

“delete from expenses” removes any data which may have been in expenses before. Perhaps from a previous month?

“load data local infile” loads the data from your text file. Change the text file path to the appropriate one for your file.

Step 5) Query Query Query

Below are a bunch of questions you might want to ask about your expenses. In the code you’ll see how those questions are translated into SQL and how the answer looks for the sample data I intered into the table.

How much did I spend in each tag? I’d like the data in descending amount spent.

mysql> select tag, sum(amount) as mysum from expenses group by tag order by mysum desc;

 +-------------------+--------+
 | tag               | mysum  |
 +-------------------+--------+
 | Food-Normal       | 722.64 |
 | Food-Out          | 449.59 |
 | Wedding           | 205.21 |
 | Household         | 125.73 |
 | Recreation        |  76.63 |
 | Utilities         |  70.34 |
 | Medical           |  40.00 |
 | Food-Entertaining |  32.54 |
 | Car               |  27.72 |
 | NULL              |   NULL |
 +-------------------+--------+
 10 rows in set (0.00 sec)


How Much did I spend total?

mysql> select sum(amount) from expenses;

 +-------------+
 | sum(amount) |
 +-------------+
 |     1750.40 |
 +-------------+
 1 row in set (0.00 sec)


How much did I spend each week?

mysql> select week(date), sum(amount) from expenses group by week(date) order by week(date);

 +------------+-------------+
 | week(date) | sum(amount) |
 +------------+-------------+
 |       NULL |        NULL |
 |         39 |     1421.73 |
 |         40 |      328.67 |
 +------------+-------------+
 3 rows in set (0.00 sec)


How much did I spend in each category and subcategory?

mysql> select tag, subcategory, sum(amount) from expenses group by tag, subcategory order by tag,subcategory;

 +-------------------+---------------+-------------+
 | tag               | subcategory   | sum(amount) |
 +-------------------+---------------+-------------+
 | NULL              | NULL          |        NULL |
 | Car               | Gas           |       27.47 |
 | Car               | Parking       |        0.25 |
 | Food-Entertaining |               |       32.54 |
 | Food-Normal       |               |      722.64 |
 | Food-Out          |               |       34.42 |
 | Food-Out          | Work          |      415.17 |
 | Household         |               |       26.73 |
 | Household         | Garden        |       33.33 |
 | Household         | Hygiene       |       38.79 |
 | Household         | Repair        |       26.88 |
 | Medical           |               |       40.00 |
 | Recreation        |               |       10.00 |
 | Recreation        | Books         |       10.99 |
 | Recreation        | Music         |       30.00 |
 | Recreation        | Video games   |       25.64 |
 | Utilities         | Internet      |       70.34 |
 | Wedding           | Wedding Dress |      205.21 |
 +-------------------+---------------+-------------+
 18 rows in set (0.00 sec)

What percentage of my total spending did I spend in each category?

mysql> select tag, sum(amount)/1750.40 as mysum from expenses group by tag order by mysum desc;

 +-------------------+----------+
 | tag               | mysum    |
 +-------------------+----------+
 | Food-Normal       | 0.412843 |
 | Food-Out          | 0.256850 |
 | Wedding           | 0.117236 |
 | Household         | 0.071829 |
 | Recreation        | 0.043779 |
 | Utilities         | 0.040185 |
 | Medical           | 0.022852 |
 | Food-Entertaining | 0.018590 |
 | Car               | 0.015836 |
 | NULL              |     NULL |
 +-------------------+----------+
 10 rows in set (0.00 sec)

This is the same as sum by tag except I divided sum(amount) by the total spent which was calculated earlier. Here you have basically what you need for YMOYL summary.

How much did I spend at each store?

mysql> select store, sum(amount) as mysum from expenses group by store order by mysum desc;

 +---------------------+--------+
 | store               | mysum  |
 +---------------------+--------+
 | Kroger              | 524.61 |
 | Starbucks           | 400.30 |
 | Jo Ann Fabric       | 205.21 |
 | Co-op               | 141.74 |
 | Trader Joe's        | 105.63 |
 | Comcast             |  70.34 |
 | Rite-aid            |  40.00 |
 | English Gardens     |  33.33 |
 | Ark                 |  30.00 |
 | Rite Aid            |  28.49 |
 | Marathon            |  27.47 |
 | Carpenter Bros      |  26.88 |
 | Kmart               |  26.73 |
 | Target              |  25.64 |
 | Jersualem Garden    |  15.37 |
 | Amazon.com          |  10.99 |
 | Damon's Grill       |  10.52 |
 | Salvation Army      |  10.00 |
 | Zingerman's         |   7.25 |
 | Colin's Coffee      |   5.30 |
 | Coney Island        |   4.35 |
 | Parking 5th&William |   0.25 |
 | NULL                |   NULL |
 +---------------------+--------+
 23 rows in set (0.00 sec)

And that’s all there is to it. Not as pretty as Quicken, but it’s way more flexible in terms of how I organize my data and what questions I ask of it.

If there’s anything in this tutorial that doesn’t make sense or if there’s a question you’d like to ask about your data that isn’t listed here, leave a comment and I’ll update this tutorial.

Tags: , , .
Posted at 5:09 pm | No Comments »

How to Get Organized When You Don’t Have Time to Get Organized

Date Posted: October 14th, 2009

In a perfect world you’d be able to take all the time in the world to set up your stuff management system. But your world isn’t perfect. Every moment seems to be eaten up by important things. You certainly can’t find a block of time in your day any larger than 15 minutes. If that’s the case for you, and you’d still like to have some sort of system in place, then this post is for you.

I do have one big assumption: you aren’t currently making use of your in-between time. By in-between time, I mean the time spent waiting in line at the post office or while you’re driving to and from work or class or that five minutes between when you get home and your next scheduled task. These are the moments this techniques utilize.

I have another smaller assumption: you don’t have a deadline for when your system needs to be totally in place. If you really don’t have the ability to take a large chunk of time out in the beginning, you can’t expect to be off and running any time soon.

So, with that, here’s the technique.

Step 1: Day dream During those in between moments visualize what your system will look like. How it would make you feel to be using it. What elements will it have. Get excited about it. The more clarity you can get the better. You don’t need to write anything down yet, so you can do this anywhere.

Step 2: Read Getting Things Done This system is probably the best for the person who feels swamped. It’ll give you a method for doing things more efficiently so that you may have a few extra moments to do some long term planning. You can get the book from the library or your local bookstore in book form or audio form. If you get the book form, keep it with you at all times. It’s one of those reads that doesn’t take much to pick up where you left off. If you get the audio version you can play it during your commute or your run or whatever.

Step 3: Day dream Some more, maybe with a pencil Focus on clarity. What exactly do you want from your system. When you get the feeling you know what you want, take 10 minutes somewhere… anywhere… to jot it down. Set a timer if you have to so you don’t spend more time on this task than you want to.
The main question to answer here is, what supplies do I need to purchase?

Chances are you’ll probably need:

  • A physical planner that holds 5.5inx8.5in sheets
  • 8.5inx11in paper
  • Three hole punch with movable hole punchers
  • A paper guillotine (check to see if your workplace already has one)
  • Nice Pen
  • Nice Pencil
  • Divider Stickers
  • Heavier card-stock paper (8.5inx11in) for turning into dividers
  • “Today” tabs

Step 4: Purchase items when convenient Keep your shopping list with you. Whenever you’re in the appropriate store where you could buy these things check to see if they’re there. Don’t make a separate shopping trip unless you have time to spare. Remember, there’s no deadline for getting this done. Do it when it’s convenient

Step 5: More day dreaming maybe with a pencil Same deal as before. Don’t spend too much time writing down what sheets you need for your physical planner. (Take as much time as you want to think, though. That isn’t wasting any time.) Action pages? Waiting for pages? Shopping list? Agendas? Figure this out. Then write down your list. Set a timer.

This might not be a bad time to browse DIY planner’s set of pages. Remember, you’ll want to print the 2-up version. It’ll save you a lot of hassle.

Step 6: Print, cut, and hole punch your pages Here you might want to set aside 20 minutes. But maybe you could combine this task with watching TV or something. You can also spread this task out over several days. Do the printing one day, cutting another, hole punching yet another. Again, there’s no deadline here.

Step 7: Fill in your planner during your in between time While you’re waiting in line at the grocery store, write down some tasks you need to do when you get home. Same thing when you’re waiting for a movie at the movie theater, or while you’re waiting for the all-staff meeting to get started. Use the minutes to empty everything stored in your head.

Step 8: If you can spare it, do a weekly review But maybe limit your time to 20 minutes. Only recopy pages that are mostly full. Or don’t even recopy, just add to it. When one’s finished you can get rid of it. Make it as sparse a review as possible. Using a timer’s a good idea to keep it from eating your day.

Using this method it’ll probably take you quite a while to get your system up and running. Maybe a month or two. But that’s OK because at least in a month or two you’ll have a working system. If you don’t do anything, 2 months from now you definitely won’t have a system. And maybe along the way you’ll find that you actually do have more time to spare than you realize. Maybe you’ll be able to get your system up and running way earlier than you expected to. :)

Tags: , , .
Posted at 10:43 am | No Comments »

« Older EntriesNewer Entries »`



Follow Me