Tableau Tip: Aligning Text and Shape inside a single cell (KPI Indicators)

Common way of putting text and shape in a single cell in Tableau  uses  Shape as mark type and the value  as Text.  Increase the column width and you have a somewhat usable view.

In the above example, I am using a dummy status calculation for color and shape selection.

Status Calculation

While this might be usable in simple situations, the problem will be evident if you resize the view.  The shape will be always displayed at the center and there is no option to make it align left or right. (Text can be aligned). Half of the cell space is unused and the cell is not aligned with the column header. I have added column dividers to make it more evident.

We are going to align the Text to left and Shape to right. In order to do this we need to create two dummy measures. (This can be achieved using an existing measure, but that will be more complicated to understand as an example). Create two measures named ‘Shape Alignment’ and ‘Text Alignment’ with values 1 and 0 respectively and AVG as default aggregation method. Drag them to columns and select ‘Dual axis’ for the second measure.

 

Make following adjustments to the view and Select ‘Synchronize Axis’ by right clicking one of the axis


Text Alignment View:

  • Mark Type :  Text
  • Label : Sum(Sales)

Shape Alignment View:

  • Mark Type :  Shape
  • Color : Status
  • Shape: Status

This will give us Left aligned Text and Right aligned shape; but we can do more to make it visually pleasing.

Adding some padding

One good thing about this technique is that you can  design the view in the exact way you want. For example, we will add some padding to left and right so that the text and shape are aligned with the order year header. We will do this by using a fixed start and end points for the axis.  I am using  -1 as start and 1.5 as end in this case, but you might have to change these values for your use case.

This will result in the following view

 

Remove grid lines and zero lines for columns, hide the header for text alignment and shape alignment and enable row grid lines.

Here is the final view. You can download the workbook from Tableau Public .

You may also like...

Leave a Reply

Your email address will not be published.