How do I use Calculated Fields to Change Tooltip in Tableau?
In last week’s Thursday Tableau Tip from The Information Lab Ireland, we showed you how to build a Grouped Bar Chart in Tableau. For this week’s blog we are going to look back at that Bar Chart and tidy up one particular aspect of it.
You might recall that the only month in which our imaginary company, K Good Company, made a loss was October. On our visualization’s Tooltip this was narrated as “In October we made a Profit of € -10,000”.
While most people would understand what that meant, Data Visualization is all about clarity and so we need to be clearer.
Simply put, we need to change the current narrative from the example above to “In October we made a Loss of €10,000”.
Create a Calculated Field
We will do this by creating not one but two calculated fields in Tableau with very simple formulas. One will change the word “Profit” to “Loss” on our tooltip when required and the other will remove the minus from our tooltip when required.
We start off by selecting Create Calculated Field from our drop down menu in Analysis (see above).
Give your Calculated Field a Title
Given that we might be creating more than one Calculated Field, it is always best to give it a title straight away. In this case we are calling our Calculated Field Profit/Loss.
We then create our formula: IF SUM (Profit) >0 THEN “Profit” ELSE “Loss” END
Simple enough. Click OK and you will see your new Calculated Field pop up in your Measures. You will then need to bring the new Profit/Loss pill into your marks card.
Open up your Tooltip (make sure you are working with the correct one SUM (Profit)).
Now you need to replace the word “Profit” with your new Calculated Field <AGG(Profit/Loss)> which contains all the information Tableau needs to make the distinction you want.
Click OK and your change is in the proverbial back of the net.
There still remains the small problem of the minus before the figure – €10,000.
We will follow the same steps as before but this time we will create a different formula and remember give it a title, Plus/Minus, to distinguish it from the other Calculated Field.
Again it’s nothing to complicated: IF SUM ([Profit]) <0 THEN – SUM ([Profit]) ELSE SUM ([Profit]) END
Bring your new Measure into the Marks Card and again you will need to edit your Tooltip, this time replacing <SUM(Profit)> with <AGG(Plus/Minus)>
Click OK and check that everything is in order.
The Information Lab (“TIL”) is a Gold resale partner of Tableau and Alteryx and offers related consulting and training across seven territories in Europe. TIL has offices in Ireland, the UK, Germany, France, Italy, the Netherlands and Luxembourg.
Clients include Coca-Cola, Close Bros Bank, PepsiCo, Deloitte, UBS, Solar Turbines & Boston Consulting Group. The Information Lab has worked with Close Brothers Bank to support their use of Alteryx for compliance with IFRS 9.
The Information Lab Ireland is at the forefront of creating a data-driven culture in Ireland. As part of its vision, The Information Lab Ireland regularly hosts free events throughout the country to show how being data-driven can improve decision making and lead to a better understanding of the world around us.
Tableau is the gold standard for intuitive, interactive visual analytics and an established enterprise platform. Over 54,000 customers have adopted Tableau to answer more questions of their data.