Showing posts with label Hacks. Show all posts
Showing posts with label Hacks. Show all posts

Friday, December 11, 2015

Cell Level Formatting in Tableau

I have to start this post be saying 'Please dont treat Tableau like Excel'.  They are different tools designed for different purposes.  Excel is a spreadsheet-making tool.  Tableau is a data visualization tool.  If this is your only use case for Tableau then you are doing it wrong.  This technique should be used only when absolutely necessary.

Cell-level formatting is a challenge in Tableau because whenever you introduce more than one measure into a text table you need to use the Measure Names and Measure Values fields.  They are like 'bucket' fields that contain all of your measures in one.  If you are confused by these read this KB article.

The problem with that is you only get one Marks card for Measure Values, which means only one Color shelf, so you cannot add a different field on Color for each of the Measures you are including (they will all get colored by one Field).

So what do we have in our bag of Tableau tricks to get us multiple Marks cards?  Add more measures to the Rows or Columns!  Each measure you add to Rows or Columns creates an axis, and in turn each axis gets its own Marks card.

We will use this to our advantage by creating an axis of '1' for each column we want to have.  You can use the Number Of Records field, or you can create a new Calculated Field and just stick '1' into it:


Use the MIN of this field and add as many of them to the Columns as you need for your view (1 field = 1 measure/column).

Then change the mark types to Text.

Then choose the Marks card label for the first MIN(One) and add your measure to both Text and Color.  Repeat for each measure you want to have a column for.

Now we just need to tidy things up.  You can make the columns skinnier by just adjusting the line that separates the axes on the bottom, and then right-click on an axis (or one of the measures on Rows) and uncheck 'Show Header'.

Now you might be thinking 'What about the Labels..?!' this is where we use a dashboard and some floating text objects to label each column for us.  Drag in a Text object, make it 'floating', and then drag and dop exactly where you want it to go.  Rinse and repeat for each label.


Tip:  use the area in the lower left to adjust the pixel values for  'y' and 'h' to align them all perfectly.
Tip 2:  use a fixed-size dashboard so your labels always stay exactly where you placed them.  If you use Automatic sizing, then the relative placement of your fixed and floating objects will change and you label placement will get messed up.

Booyah.  Cell level formatting in Tableau.

Note:  In this example I use Text for all mark types and I color each column.  There is nothing stopping you from making some columns Shapes or Highlight Boxes (using the Bar mark type) or not coloring some columns at all (I will include an example in the workbook you can download).  This is example just shows the framework which you can extend upon.

Workbook: https://app.box.com/s/cz4zjhnei5hnhtxyepg7e9fj9vxjf3oo

-The Don

Special call out to the O.G. Scott Wasserman for figuring out this genius use of multiple mark cards when tableau introduced Dual-Axis charts way back in the day.  Floating objects in dashboards further simplified the original workaround which required far more steps to get labels for the columns.  Maybe some day we will be able to use Measure Names and Measure Values in calculated fields and this workaround wont be needed anymore, but until then, use it but dont abuse it.



Monday, September 29, 2014

More than 16 columns (row headers) in Tableau

As you well know if you are reading this post, Tableau only allows 16 row headers/labels in a single visualization before it starts concatenating the header values.  The default is actually 6 headers until it starts to concatenate but this can be increased if you go to the menu Analysis->Table Layout->Advanced

























But what if you want more than 16?

Note 1:  I first want to say that no good analysis can stem from a text report that has 16+ columns in it.  However I understand sometimes folks just want to show some drilldown detail that can be exported to csv/excel/etc.

Note 2:  If you are using this workaround to be able to display/export larger tables from Tableau, it is not a good idea to treat a Data Visualization application like an ETL tool.  You are using Tableau wrong.

Note 3: This is not supported.  At all.  If something breaks please dont email Tableau Support about it.  This hack comes 'as-is'.

Note 4:  I think this hack will work if you want to put a few extra columns (maybe like 20 total), but dont go crazy with it and try to put 50 columns out there.

The only way to do this is to hack the XML of the .twb (wookbook) file.  If you save your file as a .twb, then right-click on it and choose to open it in a text editor (I like Notepad++), you can search for the term attr='row-levels' and you will find this section of the XML:











If you change those numbers to whatever else you want, then save your file (be sure if you choose 'save as' that you save as the file type 'All files' in the dropdown at the bottom and add '.twb' to your file name - i.e. dont save it as '.txt').  When you open it in tableau next, you will be able to add that many dimensions to the Rows shelf before it starts to concatenate the headers.

Result (I typed in 21):









Note:  You can only open .twb files to see the XML in a text editor.  If you have already saved your file as a .twbx you can right-click on the icon and choose 'unpackage'.  This will create a .twb file and a folder with all the excel files/extracts/images/etc that were part of the packaged workbook.
 
Note:  If you go back into Analysis->Table Layout->Advanced it will still say the last numbers you entered in the UI, not the new numbers you manually entered into the XML, just ignore them.
Again, I do not condone this behavior, but sometimes you just need 'a fix'.

Note:  Dimension headers will never get a scroll bar in Tableau (only items in the 'pane' are scrollable).  Tableau always expect you are building a chart and doesnt expect you will display tons of text columns.  Therefore you must put your view on a dashboard and fix the size to be big enough to hold your entire view (width wise).  I like to set mine to 'Range' and then set a Min size but no Max (the height on the Min can be small, but the width must be large enough to fit all your fields).
























Workbook:  https://app.box.com/s/760tvsfnko1cdxj2ghsf

-The Don Data