'Hacking' Tableau's XML

*Disclaimer: ALWAYS make backups of your files before editing the XML. Should you replace even one comma improperly, you run the risk of bricking your file. Be safe. Be smart.

Born too late to explore the earth. Born too early to explore the galaxy. Born just in time to explore the world of data.

At almost every company I’ve worked for, I’ve heard the phrase, ‘data driven decision making’. Companies now are realizing the gold mine they sit on that is their SQL server or GP or Teradata DB and with this realization comes the need for deeper and deeper data dives in the search for the ‘unknown’. Subtle nuances of your consumer base or aspects relating to operational efficiency are just sitting within gigabytes upon terabytes of data waiting to be discovered.

We’ve come a long way from Excel as the analytics weapon of choice as the complexity of data operations increases. As of February 2016, 24 distinct analytic tools have made it onto the Gartner Magic Quadrant. 

With so many options available the potential to fall into a paradox of choice is pretty high and, as I’ve seen, some departments default back to what they know: Excel. Even worse, in the extreme opposite case, departments purchase one of every flavor which makes standardization and knowledge transfer a nightmare; but that’s a topic for another day.

 

Today, we’ll be focusing on one of my favorite tools: Tableau. At a price point that allows even Mom & Pop shops to take their business analytics to the next level and a learning curve that can have a virgin user building beautiful visualizations in a matter of hours, it’s one of the best analytics tools money can buy these days.

Now, out of the box analytics tools are great but, sometimes, they fail to scratch the itch for exploration that open source tools like d3.js or leaflet are able to. Tableau might seem to fall into the former category; however with a little ingenuity and a sense of adventure, you too can break Tableau.

 

At its core, Tableau is just a big XML file, so let’s see what that looks like.

To start, we’ll change the extension of our packaged workbook (.twbx) to a .zip. Within the zip file we have a .twb which, when opened in a text editor (I’m using Sublime Text 3) will show you what Tableau’s XML structure for your workbook looks like.

This image is of a completely blank workbook so you can see just what you’re starting with when you begin to create a dashboard. Even without any deep knowledge of what XML is, Tableau’s structure is fairly straight forward. What we’ll focus on, today, is making global formatting adjustments to your dashboard. For that, let’s focus on the “style” section. In the above image, it’s completely empty which is fine because we haven’t started building yet. Once you do, it will look something like this:

As you can see, the “style” block has changed quite a bit. Let’s break this down a bit. Starting from the top, we have something called “mark”. Remember in the base XML image, there was a “card” type called “marks”? Well that’s exactly what this is calling! When you drag measures into the view and create a chart type, this <mark class = ‘something’ /> value is encoded as your selection. In this case, it’s “Area” for area chart.

Moving down to our next selection, we have something called “font-family”. Now, this should be pretty self-explanatory but don’t assume too much! Unlike “mark” which is a high level encoding of how to display your whole chart, “font-family” is area specific. This means that different areas of your worksheet or dashboard can have different encodings of “font-family” depending on your selection. Here, if you look two rows above, you’ll see that this font selection affects the “datalabel” which is related to your selection (within the marks card) of “text”.

In our last selection block, we see that <mark class = ‘something’ /> text block again. Well, above we were stating that we would like for an Area chart to appear in relation to our data. Here, however, we’ve added in lower grain detail as to what else (beyond just the measure values we’ve placed on our rows or columns) we would like for it to show. Now, take a look at the left most word of each row. We have “Color”, “Tooltip”, and “LOD”. Now take a look back at the Marks card. See the relation? This is where we are encoding the dimensions or measures we would like to color this chart by (Color), have the chart sliced by (LOD), and have encoded in the hover-over tool-tip (Tooltip).

This is all well and good but what’s the point of knowing all of this besides the obvious picking up chicks at parties? (That works, right?) Well, let’s start mucking about and see what we can make Tableau do. If we were to change the
<mark class = ‘Area’ /> to, say, <mark class = ‘Bar’ />, what do you suppose would happen?

 

Here is our initial dashboard with the settings in the above image:

And here it is with the change to the marks encoding:

Like magic, we’ve updated our dashboard without ever opening the file. In all reality, though, it would take just as much time to open up the dashboard and change the chart type. Plus you do not run the risk of accidentally deleting something in the XML that renders your file useless. So, honestly, why is this useful?

In instances where your goal is to edit a single item, it’s not. However, let’s say you manage a suit of tableau files for your reporting team. Each of these files has a number of dashboards, all with multiple sheets and different chart types. Let’s say a change order comes through for chart types of Bar to be changed to Line. Or your brand team now requires all fonts used in reporting to be Arial 12pt. Or you’re using hosted data sources and you need to change your connection from Source_A_Prod to Source_B_Prod. The list goes on and on. In these cases, XML editing is the most efficient means of producing those results. With a simple Python or Powershell script, you could take a job like that from 3 hours down to 3 seconds. The limits of XML editing are only limited by your imagination…and what’s functionally possible within Tableau’s XML structure. So there you have it. Good luck and happy (XML) hunting to all you curious data explorers out there!