Saturday, August 15, 2015

Use IFTTT, Google Calendar and Google Sheets for Mileage Deduction

I keep a Google Calendar for my business appointments and was looking for a way to use the location field to automatically figure out my mileage for end of the year tax deductions. There are products out there that will let you do this but I was able to do this for free by bringing together two methods I found on the web - an IFTTT recipe and a Google Sheets formula.

The IFTTT recipe fires off when an event starts. It sends the event info (including address) to a Google sheet, appending the event to the last row of the spreadsheet. Pretty much all of the appointments in my calendar are tax deductible but I go in and delete the occasional ones that are not deductible from the spreadsheet. You can also set up this IFTTT recipe to only fire off when you have a certain keyword in your event, which is useful if your calendar mixes deductible and non deductible. Simply append a word to your event title for the items that are deductible.


You will need to add this script (stolen from here and slightly adapted to deal with the #errors that appear) to the spreadsheet:

function distance(pointa,pointb) {
  var randnumber = Math.random()*5000;
      Utilities.sleep(randnumber);
      Utilities.sleep(randnumber);
  var directions = Maps.newDirectionFinder()
     .setOrigin(pointa)
     .setDestination(pointb)
     .setMode(Maps.DirectionFinder.Mode.DRIVING)
     .getDirections();
  var route = directions.routes[0];
  var txtA = route.legs[0].distance.value;
  return txtA;
}

You will have to add a column that has the starting address for your drive. This is easiest to populate if you always start from the same address but you can always change each item individually. Unfortunately this system only works for round trips, though with a little effort you can adapt this for a separate starting and ending address.

You then add a column to the end that has this formula.

=distance($B2,$C2)/1609*2

$B2 and $C2 are the two cells containing the starting address that you add and the address of the event from Google Calendar. This formula computes the distance in yards, converts that to miles and then multiples by 2 to figure out the round trip.

Add a cell at the end that add up the distance column and then another cell that multiplies by the IRS' current mileage rate (57.5 cents in 2015) and you get a useful little spreadsheet for your end of the year tax needs!