How to Create a Dynamic Measure with Multiple Number Formats in Tableau

By: Eric Parker

Pro Headshot.jpg

Eric Parker lives in Seattle and has been teaching Tableau and Alteryx since 2014. He's helped thousands of students solve their most pressing problems. If you have a question, feel free to reach out to him directly via email.

You probably know that you can only set one number format per field in Tableau. That means that if you create a dynamic measure driven by a parameter (check out this blog post for details) you have to choose a number format. You could choose percent, decimal or currency, but you can’t get the format to swap.

I am going to start with this framework for my worksheet:

 
146-1.png
 

Let’s say I’d like to be able to compare Sales (currency), Quantity Sold (standard integer) and Profit Ratio (percentage).

First, I’ll create the parameter with the three options.

 
146-2.png
 

Next, I’ll create the calculated field that swaps between the three measures.

 
146-3.png
 

Notice how the axis and number format looks okay when Quantity Sold is selected.

146-4.png

However, the chart doesn’t look as great when Profit Ratio is selected.

146-5.png

Here’s how we can fix that.

First, let’s multiply the Profit Ratio of the Dynamic Measure calculation by 100.

 
146-6.png
 

Now, we need to create Prefix ($) and Suffix (%) fields.

Only the Sales field has a prefix.

 
146-7.png
 

And only the Profit Ratio field has a suffix.

 
146-8.png
 

Now it’s time to put all these pieces together.

First, we can remove the axis label.

146-9.png

Next, we can insert the parameter into the title to make it dynamic.

146-10.png

Then we’ll add the [Prefix], [Dynamic Measure] and [Suffix] fields to the Label section of the Marks card.

146-11.png

The labels will look weird at first, that’s okay. We can edit the label by selecting the Labels section of the Marks card and selecting the ellipsis.

 
146-12.png
 

By putting all three fields on the same line, we can build cohesive looking labels.

146-13.png

And the best part is, because we never altered the number formatting, it’s automatic so it will show decimals for Profit Ratio but not for Sales!

146-14.png

Thanks for checking out this post! As always, feel free to reach out with questions or book an office hour to work together!

Using SQL for Tableau Performance Improvement

Week to Date vs. Previous Week to Date in Tableau (WTD)

0