Saturday 25 October 2014

Tableau tech - converting from reading to rates

Technically, I didn't make my life easier by starting with an irregular series of meter readings of electricity and gas for plotting in Tableau. 

I was determined that Tableau should do all the work. I just provided a .xls file with dates and meter readings, rather than tidy up in Excel/OpenOffice. Tableau read and understood the file happily enough - though it thought 'Day' was a date rather than a reading of daytime electricity, it was simple enough to move the variable from the 'dimensions' to the 'measures' section.

I had to convert the data from readings into some sensible units within Tableau: I chose daily consumption rates.

This took 2 steps:
1) Convert the dates of the readings into number of days:
Define the measure 'DayDiff'  as 

DATEDIFF('day',lookup(Max([Date]),-1),max([Date]))

2) Then calculate the rates. For gas there is a multiplier to get to kWh (9.8805 according to my supplier)

GasRate
9.8805 * (Max([Gas]) - lookup(max([Gas]),-1))/[DayDiff]

Why you have to have the aggregate function (Max) around the variable, I don't know, but Tableau insists.

No comments:

Post a Comment