Dynamic Label Formatting in Tableau

Sometimes there is a need to display different data formats within the same visual.  However, if there are multiple formats, such as currency and percentage in the same visual, how does Tableau know what format to display for each underlying data object?  For example, a college may want a dashboard user to have the ability to toggle between displaying Student Headcount (integer), Tuition Revenue (currency), and Course Success Rate (percentage) in a bar chart.  You can leverage the following parameter to drive this interactivity:

Dyn-1.jpeg

This Metric parameter can then be referenced in the following Selected Metric calculated measure:

Screen Shot 2021-03-17 at 12.14.14 PM.png

Adding the Selected Metric measure along with course subject to a column chart yields the following visual:

Screen Shot 2021-03-17 at 12.14.25 PM.png

At this point the user can select between the three measures, and the chart will update accordingly.  However, if data labels are required to be displayed on the chart, dragging the Selected Metric to the Label card displays only one data format for all three measures.  While Headcount displays correctly as integer format, the Course Success Rate does not display in percentage format:

Screen Shot 2021-03-17 at 12.14.35 PM.png
Screen Shot 2021-03-17 at 12.14.43 PM.png

To resolve this a separate calculation can be created exclusively to serve the Label card of the visualization. This calculation will do the following:

  • Convert the number to text

  • Add any prefixes and suffixes ($, %, etc.) that might be needed for each individual metric

  • Perform the appropriate formatting for each metric

Screen Shot 2021-03-17 at 12.14.54 PM.png

Once the Dynamic Data Label object is placed on the Label marks card, the selected metric will now display with the appropriate formatting:

Screen Shot 2021-03-17 at 12.15.05 PM.png

There you have it! The best part is this solution can work for any Tableau dashboard solution as it uses native, out of the box functionality available in Tableau Desktop. Please comment and let us know your thoughts!

Previous
Previous

Filtering Web Intelligence Queries Using External Lists